0


I already have two web pages designed for 404 and 500 error pages in web.xml

 <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/error/404.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/WEB-INF/error/500.jsp</location>
    </error-page>

I want to redirect to a predesignated page for all the other errors.
Please help. Thank you

Dil.
  • 1,996
  • 7
  • 41
  • 68

2 Answers2

1

This should be sufficient, along with few customer error related pages, you can add default page. So all error other than 404, 500 , will be redirected to generic page error.html

<error-page>
    <location>/error.html</location>
</error-page>

or more customized, using Exception class, can be your custom exception class as well.

<error-page>
  <exception-type>java.lang.Throwable</exception-type>
  <location>/error.html</location>
</error-page>

So code becomes,

<error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/error/404.jsp</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/error/500.jsp</location>
</error-page>
<error-page>
    <location>/error.html</location>
</error-page>
Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116
1

You could do the following to tackle 400 and 500 status error codes.

Add the below lines in web.xml files

<error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/error/404.jsp</location>
</error-page>

<error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/error/500.jsp</location>
</error-page>

In addition to above, you can also use the Exception type: See below:

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/WEB-INF/error/exception.jsp</location>
</error-page>

The difference is: <error-code> and <exception-type> depends on which is used.

Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51