Servlet TomCat 8.5.2的错误404

时间:2017-09-20 05:03:43

标签: java html tomcat servlets

我已正确安装TomCat,因为我可以访问Localhost:8080上的主页。但是,当我尝试运行我的servlet时,它给出了错误404.

HTTP状态404 - 未找到

输入状态报告

Message / CS3220 / RequestSummary

描述源服务器没有找到目标资源的当前表示,或者不愿意透露该目标资源是否存在。

这是我试图运行的脚本的一部分。

package LAB02;


import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/RequestSummary")
public class RequestSummary extends HttpServlet {
    private static final long serialVersionUID = 1L;

public RequestSummary() {
    super();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    //set type
    response.setContentType("text/html");

    //Get a refernece to PrintWriter that lets us talk to the client
    PrintWriter out = response.getWriter();

    //generate html

    out.println("<!DOCTYPE html>");
    out.println("<html lang=\"en\">");
    out.println("    <head>");
    out.println("       <meta charset=\"utf-8\">");
    out.println("        <title>Response Summary</title>");
    out.println("       <link rel=\"stylesheet\" href=\"https://bootswatch.com/paper/bootstrap.min.css\">");
    out.println("       <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
    out.println("    </head>");
    out.println("    <body>");
    out.println("       <div class=\"container\">");
    out.println("       <div class=\"jumbotron\">");
    out.println("               <h1>Request Parameters <small>Lab 1</small></h1>");
    out.println("       </div>");
    out.println("       </div>");
    out.println("</body>");
    out.println("</html>");


}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
}

}

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>CS3220</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>
</web-app>

如果您还需要其他任何帮助我,请告诉我。我对此非常陌生,对这个问题还没有很好的理解。谢谢!

0 个答案:

没有答案