3

I want to display the default Tomcat error page in JSF 2.0 (MyFaces) application when exception is thrown.

I added following lines to web.xml:

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/ErrorHandler</location>
</error-page>
<context-param>
    <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
    <param-value>false</param-value>
</context-param>

And here is ErrorHandler servlet:

public class ErrorHandler extends HttpServlet {

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Error");
    }
}

But instead of the default Tomcat error page an empty page is displayed with error code 500.

When I try to access ErrorHandler servlet directly through URL, it works OK: Tomcat error page is displayed.

So I guess the reason is JSF error handling mechanism? What am I doing wrong?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Vladimir M.
  • 1,049
  • 1
  • 10
  • 24

1 Answers1

0

If you want to display the default error page of the app server, just remove the error page entry from your web.xml and set the context init-parameter javax.faces.PROJECT_STAGE to Production.

Ravi Kadaboina
  • 8,494
  • 3
  • 30
  • 42