Servlets Servlet中404错误的处理
我试图根据状态代码重定向到不同的错误jspServlets Servlet中404错误的处理,servlets,http-status-code-404,Servlets,Http Status Code 404,我试图根据状态代码重定向到不同的错误jsp statusCode=(整数)req.getAttribute(“javax.servlet.error.status\u code”) 但它抛出了一个空指针错误。 我的web.xml看起来像 <exception-type>404</exception-type><location>/AppExceptionHandler</location> 404/AppExceptionHandler 我认为
statusCode=(整数)req.getAttribute(“javax.servlet.error.status\u code”)
但它抛出了一个空指针错误。
我的web.xml看起来像
<exception-type>404</exception-type><location>/AppExceptionHandler</location>
404/AppExceptionHandler
我认为web.xml
中的条目不正确。它应该如下所示。异常类型不应该是code,而是一个类。如下所示
<error-page>
<error-code>404</error-code>
<location>/AppExceptionHandler</location>
</error-page>
异常类型包含完全限定的类
Java异常类型的名称
javax.servlet.ServletException Error.jsp
<error-page>
<error-code>404</error-code>
<location>/AppExceptionHandler</location>
</error-page>