开发者

Replacing JavaServer Faces Error Pages

Is it possible to replace the standard error pa开发者_StackOverflow中文版ges from JavaServer Faces such as

500 Internal Server Error

?

These include information such as the stack trace, etc. But for the users, when the page is in Production Mode, I want to show a friendlier page saying that the request did not succeed.


The development stack trace is probably coming from your JSF implementation. The code for disabling it will be specific to the impementation. For MyFaces in Servlets, use this init parameter in your web.xml:

  <context-param>
    <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
    <param-value>false</param-value>
  </context-param>

If you're using the Sun implementation (Mojarra), there may be some com.sun.faces... keyed parameter.

You may also want to check the value of Facelets init parameter facelets.DEVELOPMENT (make sure you haven't set it to true).

To specify an error page, you can use the usual container mechanisms. For Servlets, this would be by specifying a error pages in web.xml, keyed to either exception types or error codes. To catch all throwables...

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

You might find additional vendor-specific support for error handling in the JSF implementations - you'd have to check their documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜