Tomcat v8+Servlet v3.1 在 运行 一个 servlet 上给出 404 错误

Tomcat v8+Servlet v3.1 giving 404 error on running a servlet

这是我写的示例 servlet,没什么特别的:

@WebServlet("/SimpleServletPath")
public class SimpleServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Hello");
    }
}

我在计算机上使用外部安装的 Tomcat v8.0,它在查询 http://localhost:8080/.

时给出了正确的页面

Eclipse Luna 中使用的 Dynamic Web Module3.1。此外,由于我使用的是 @WebServlet 注释,因此我没有生成或使用 web.xml 文件。

无论我做什么,Tomcat 总是在 运行 Servlet 上给我错误。

HTTP Status 404 - /SimpleServlet/SimpleServletPath
type Status report

message /SimpleServlet/SimpleServletPath

description The requested resource is not available.


--------------------------------------------------------------------------------

我知道这听起来很傻,但我在 Eclipse 中没有选中 Build Automatically。我想这阻止了对我的项目的任何更改被构建和部署到 Tomcat.

刚刚检查 Build Automatically,现在一切正常。

Servlet 3.1 (with/without web.xml) 以及 Servlet 2.5 (with web.xml).