Search code examples
javajspservletscustom-error-pages

Displaying information about the exception in a custom 500 error jsp page


I would like :

  • to customize my 500 error page and
  • log the exception details that caused the 500,

is there a way to get this info? how do I reference it?


Solution

  • Specify error page in web.xml like this

    <error-page>
            <error-code>500</error-code>
            <location>/error500.jsp</location>
        </error-page>
    

    Then create error500.jsp as error page, use exception object to display the stacktrace like this.

    <%@ page isErrorPage="true" %>
    <% exception.printStackTrace(response.getWriter()); %>