我的项目在Jetty 6上运行得很好,但是在Jetty 7.5+上(我检查了7.5,8.1和9.0)我在Jetty启动时遇到No such servlet
异常(项目部署,我猜)。
的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>");
}
}
答案 0 :(得分: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声明的顺序并不那么严格。