Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 292
newbie Avatar asked Jun 02 '10 08:06

newbie


People also ask

How to solve the error in web xml?

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.

How do I setup an error page in Web xml?

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.


1 Answers

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

like image 186
JoseK Avatar answered Nov 04 '22 17:11

JoseK