15

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.

Narayan
  • 6,031
  • 3
  • 41
  • 45
newbie
  • 24,286
  • 80
  • 201
  • 301

3 Answers3

10

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

JoseK
  • 31,141
  • 14
  • 104
  • 131
3

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>
Mircea Stanciu
  • 3,675
  • 3
  • 34
  • 37
1

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>
ozma
  • 1,633
  • 1
  • 20
  • 28