Tomcat v8 + Servlet v3.1在运行servlet时出现404错误

时间:2015-03-10 12:28:44

标签: java eclipse tomcat servlets

这是我写的样本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/的正确页面。

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

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

HTTP Status 404 - /SimpleServlet/SimpleServletPath
type Status report

message /SimpleServlet/SimpleServletPath

description The requested resource is not available.


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

1 个答案:

答案 0 :(得分:1)

我知道这听起来很傻,但我在Eclipse中取消选中Build Automatically。我想这可以防止我的项目的任何更改被构建并部署到Tomcat。

刚刚检查过Build Automatically,现在一切都运转良好。

Servlet 3.1(带/不带web.xml)以及Servlet 2.5(带web.xml)。

相关问题