Java 添加错误页面会阻止Tomcat7中的所有servlet
我在eclipse中有一个动态web项目,它使用注释映射servlet,如下所示:Java 添加错误页面会阻止Tomcat7中的所有servlet,java,jsp,tomcat,servlets,custom-error-pages,Java,Jsp,Tomcat,Servlets,Custom Error Pages,我在eclipse中有一个动态web项目,它使用注释映射servlet,如下所示: @WebServlet("/LoginController") public class LoginController extends HttpServlet { .... } <form method="post" action="LoginController"> 我还有使用这些servlet的jsp页面,如下所示: @WebServlet("/LoginController") p
@WebServlet("/LoginController")
public class LoginController extends HttpServlet {
....
}
<form method="post" action="LoginController">
我还有使用这些servlet的jsp页面,如下所示:
@WebServlet("/LoginController")
public class LoginController extends HttpServlet {
....
}
<form method="post" action="LoginController">
这就引出了一个新问题。我的servlet不再工作了!我所有的JSP都运行良好。但是对我的servlet的所有请求都会将我带到404错误页面。例如,我可以得到一个登录表单,因为JSP工作正常。但是,当我将我的登录表单提交到LoginController
时,它会显示404错误页面
我认为可以通过使用
web.xml
文件进行servlet映射而不是WebServlet
注释来解决这个问题。但是有没有一种方法可以使用WebServlet
注释并提供错误页面?如果web.xml
可以避免显示错误页面,我会很高兴。另外,我不喜欢编辑tomcat的任何配置文件。那么,如何解决这个问题呢?删除文档类型,并使用以下web app元素声明:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
您使用的文档类型将您的web应用声明为2.3 web应用,不支持批注。删除文档类型,并使用以下web应用元素声明:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
您使用的文档类型将您的web应用声明为2.3 webapp,它不支持注释