HTTP 404错误。请求的资源不可用。我正在使用Jdk 1.8和eclipse jee mars

时间:2017-08-25 20:28:00

标签: eclipse servlets

我将我的代码放在我遇到问题的地方。

WriteToPdf1.java

import java.io.*;
import javax.servlet.http.*;
import com.darwinsys.spdf.PDF;
import com.darwinsys.spdf.Page;
import com.darwinsys.spdf.Text;
import com.darwinsys.spdf.MoveTo;

public class ServletPDF1 extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        PrintWriter out = response.getWriter();
        response.setContentType("application/pdf");

        response.setHeader("Content-disposition","inline; filename='CreatePDFFile.pdf'");

        PDF p = new PDF(out);
        Page p1 = new Page(p);
        p1.add(new MoveTo(p, 200, 700));
        p1.add(new Text(p, "Hi This is created PDF file by using Servlet"));
        p1.add(new Text(p, "by us...Bhumesh Patel...."));

        p.add(p1);
        p.setAuthor("Bhumesh Patel....");

        p.writePDF();
    }
}

的index.html

<a href="/servlet1">CLICK HERE</a> 

的web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>WriteToPdf1</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>ServletPdf1</servlet-name>
    <servlet-class>ServletPdf1</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ServletPdf1</servlet-name>
    <url-pattern>/servlet1</url-pattern>
  </servlet-mapping>
</web-app>

请帮助我在eclipse jee mars中执行此操作并尝试了几个选项但无法执行它。我已附加所有代码。请帮助。

1 个答案:

答案 0 :(得分:0)

如果在服务器运行期间更改了web.xml文件中servlet的url映射(取决于你的服务器),它将无法获取更改。尝试清理,重建和重新启动服务器。