简体   繁体   English

使用web.xml和pretty-faces重定向到自定义错误页面

[英]Redirecting to custom error page with web.xml and pretty-faces

I've encountered an interesting issue with showing custom error pages to user when using PrettyFaces. 我在使用PrettyFaces时向用户显示自定义错误页面时遇到了一个有趣的问题。

So, in my web application, I want to show a cute page with kitty and some relaxing words in case my app 'provides' any internal unexpected exception. 因此,在我的网络应用程序中,我希望显示一个带有kitty的可爱页面和一些轻松的单词,以防我的应用程序“提供”任何内部意外异常。 Here is a part of my web.xml : 这是我的web.xml的一部分:

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

And I've also tried general exception page (without error code and only location tag specified); 我还尝试了一般异常页面(没有错误代码,只指定了location标记); it also doesn't work. 它也行不通。 Instead of showing cute kitty, ugly error 500 and stack trace incoming. 而不是显示可爱的小猫,丑陋的错误500和堆栈跟踪传入。

Another thing is that I'm using pretty-faces. 另一件事是我正在使用漂亮的面孔。 So, I've tried this trick: 所以,我尝试过这个伎俩:
1) part of my web.xml 1)我的web.xml一部分

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

2) part of my pretty-config.xml 2)我的pretty-config.xml

<url-mapping id="404">
  <pattern value="/500" />
  <view-id value="/pages/error/500.xhtml" />
</url-mapping>

This trick was better, but still doesn't do exactly what I want. 这个技巧更好,但仍然没有完全符合我的要求。 Now it shows simple blank white page with nothing; 现在它显示简单的空白页面,没有任何内容; and in browser console I can see requested URL with error code 404 (but the 500.xhtml file correctly exists, i can see it in assembled .ear). 在浏览器控制台中,我可以看到请求的URL,错误代码为404(但500.xhtml文件正确存在,我可以在汇编的.ear中看到它)。

Without seeing your application, I'd have a hard time knowing what exactly is going on. 如果没有看到您的应用程序,我将很难知道到底发生了什么。 There could be any number of reasons for this (a problem in the error page itself, for instance, that causes a subsequent exception that the container hides because it's already in error state.) 可能有多种原因(例如,错误页面本身存在问题,导致容器隐藏的后续异常,因为它已经处于错误状态。)

I would check to make sure that there is not a second exception being created when accessing the 500 page, as this is a common problem for exception pages that have any kind of functionality in them. 我会检查以确保在访问500页时没有创建第二个异常,因为这是其中具有任何类型功能的异常页面的常见问题。

If you want more assistance, feel free to open a thread on http://ocpsoft.org/support/ , upload an example app that reproduces this, and we can take a deeper look. 如果您需要更多帮助,请随时在http://ocpsoft.org/support/上打开一个主题,上传一个可以重现此内容的示例应用,我们可以深入了解一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM