-1

我的项目在 Jetty 6 上运行良好,但是在 Jetty 7.5+ 上(我检查了 7.5、8.1 和 9.0)我No such servlet在 Jetty 启动时遇到异常(我猜是项目部署)。

web.xml

<servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
<servlet>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>myproject.servlets.TestServlet</servlet-class>
</servlet>

TestServlet.java

public class TestServlet extends HttpServlet {
    private static final long serialVersionUID = 3992344538270432732L;

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<body>");
        out.println("<h1>Hello Servlet Get</h1>");
        out.println("</body>");
        out.println("</html>");
    }   
}
4

1 回答 1

3

颠倒 web.xml 中的顺序解决了这个问题:

<servlet>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>myproject.servlets.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/TestServlet</url-pattern>
</servlet-mapping>

我猜以前版本的 Jetty 对 servlet 声明的顺序并没有那么严格。

于 2013-05-22T11:12:09.827 回答