I tried to use
开发者_如何学C<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/errors/error.jsp</location>
</error-page>
but i dosen't catch 404 errors. How can I catch also 404 etc. errors to that same page ? I want to catch ALL error codes to same error page jsp.
You can add an <error-code>
tag for that
<error-page>
<error-code>404</error-code>
<location>/errors/error.jsp</location>
</error-page>
UPDATE:
As per your updated question - you'll have to define EACH error-code individually in the web.xml.
Using <exception-type>java.lang.Throwable</exception-type>
will catch the error 500s but not 404s
I am using this:
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/pages/exception/sorry.html</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/security/403</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/security/404</location>
</error-page>
In Tomcat7 (might work on older versions but I didn't check)
add the error pages you want (e.g 404.jsp, general_error.php etc.)
add to web.xml (all first and then specific. adapt it to your code of course):
<error-page>
<location>general_error.php</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>404.jsp</location>
</error-page>
<error-page>
<error-code>409</error-code>
<location>error_page.jsp?error=custom_message</location>
</error-page>
精彩评论