Java Servlet HTTP状态代码404

时间:2015-01-08 11:18:37

标签: java servlets

尝试在servlet中测试方法时遇到了一些问题。以下是我存储servlet类的方法:

enter image description here

然后当我右键单击TrackNYPServlet并在服务器上运行时,我的浏览器弹出了这个URL:

http://localhost:8080/TrackNYP/servlet/servlet.TrackNYPServlet

以及错误消息:

HTTP Status 404 - /TrackNYP/servlet/servlet.TrackNYPServlet

在我的serlvet课程中:

@WebServlet("/TrackNYPServlet")
public class TrackNYPServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
}

我想知道哪个部分出了问题。有任何想法吗?提前谢谢。

2 个答案:

答案 0 :(得分:0)

您是否尝试过此网址?

http://localhost:8080/TrackNYP/TrackNYPServlet

这应该有用。

答案 1 :(得分:0)

Url不需要包名称。它应该只包含您使用@WebServlet("/TrackNYPServlet")定义的路径。所以你的网址应该是:

http://localhost:8080/TrackNYP/TrackNYPServlet

就像:

http - the protocol that you are using
localhost - host where your web server is hosted.
8080 - port where you hosted your webserver on
TrackNYP - Webapp name
TrackNYPServlet - Path which you defined in your custom code.