javaweb.xmlcustom-error-pagesdeployment-descriptor

How can I catch all errors to same page from web.xml?


I tried to use

<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.


Solution

  • 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