JSF 2.0中的WEB.XML错误页面

TGM*_*TGM 1 error-handling jsf-2

我正在使用JSF2和Glassfish 3.0.

我有一个非常简单的应用程序,我正在尝试设置一些默认错误页面404500错误.

这是WEB.XML部分:

<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>
Run Code Online (Sandbox Code Playgroud)

即使error.xhtml存在,在浏览器中我仍然得到标准HTTP Status 404 -警告.

Bal*_*usC 12

<exception-type>应指向的子类的全限定名java.lang.Exception.例如

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/expired.xhtml</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)

但你所拥有的只是HTTP状态代码.你应该使用<error-code>而不是.

<error-page>
    <error-code>500</error-code>
    <location>/error.xhtml</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我不会让404和500指向相同的错误页面.404是"找不到页面",这通常是客户自己的错误,而不是服务器的错误.获取一般错误页面而不是"找不到页面"将会非常混乱.