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?

0

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.