JSF 2.0中的WEB.XML错误页面 [英] WEB.XML error-page in JSF 2.0

查看:113
本文介绍了JSF 2.0中的WEB.XML错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF2和Glassfish 3.0。



我有一个非常简单的应用程序,我试图设置一些默认 404 500 错误的错误页面。



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>

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

解决方案

< exception-type> ; 应指向 java.lang.Exception的 。例如

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

但是你所在的只是 HTTP状态代码。您应该使用< error-code>

 <错误页> 
< error-code> 500< / error-code>
< location> /error.xhtml< / location>
< / error-page>

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


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.

解决方案

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.

这篇关于JSF 2.0中的WEB.XML错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆