WEB.XML error-page in JSF 2.0

[亡魂溺海] 提交于 2019-12-13 17:59:26

问题


I'm using JSF2 and Glassfish 3.0.

I have a very simple application and I'm trying to set up some default error pages for 404 and 500 error.

This is the WEB.XML section:

<error-page>
    <exception-type>404</exception-type>
    <location>/error.xhtml</location>
</error-page>

<error-page>
    <exception-type>500</exception-type>
    <location>/error.xhtml</location>
</error-page>

Even though error.xhtml exists, In the browser I still get the standard HTTP Status 404 - warning.


回答1:


The <exception-type> should point to the full qualified name of a subclass of java.lang.Exception. E.g.

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/expired.xhtml</location>
</error-page>

But what you've there are just HTTP status codes. You should be using <error-code> instead.

<error-page>
    <error-code>500</error-code>
    <location>/error.xhtml</location>
</error-page>

By the way, I wouldn't let 404 and 500 point to the same error page. A 404 is a "page not found" which is usually client's own mistake, not server's mistake. Getting a general error page instead of a "page not found" would then be very confusing.



来源:https://stackoverflow.com/questions/10296613/web-xml-error-page-in-jsf-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!