开发者

Globally Handle Exceptions in JSF2

I want to 开发者_如何学Csend the user to one error page whenever an error occurs, whether it be a 404, 500..etc. I was using the error-code in the web.xml but I want to trap all instances of java.lang.Throwable since I believe any error is a subclass of java.lang.Throwable. Also, when I used the error-code scheme, the stacktraces were not appearing in Tomcat's catlina.out anymore...any ideas? I wasn't sure if JSF2's ExceptionHandler API handled 404s?

<error-page>
    <error-code>404</error-code>
    <location>/pageNotFound.html</location>
  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/systemError.html</location>
  </error-page>


when I used the error-code scheme, the stacktraces were not appearing in Tomcat's catlina.out anymore

This is not the standard behaviour. Your problem is caused by something else. Perhaps it's the wrong testing methodology or perhaps you're suppressing exceptions and manually redirecting in some Filter or like. This is impossible to answer based on the as far provided information.


I wasn't sure if JSF2's ExceptionHandler API handled 404s?

Depends. If the request URL matches the FacesServlet, then it would by default throw a FileNotFoundException which eventually ends up as HTTP 500. If the request URL does not match the FacesServlet or any other servlet, then the servlet container will handle it as HTTP 404.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜