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.
The other solution is, click on your project > right-click > Java EE Tools > Generate Deployment Descriptor Stub as shown in the below image. And this will generate the web. xml file inside the WEB-INF folder with some pre-defined code as shown in the below image. And it will also resolve the error.
The error page can be either a static HTML file, or a JSP, or servlet. To map the error page to an HTTP error response status code at design time, you use the <error-code> tag within the <error-page> tag in the web. xml deployment descriptor to specify the error code to respond to.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With