如何优雅地处理 JSF 应用程序故障?
如果是我的 JSF 应用程序,我有时会遇到一个错误,例如,它会损坏某处的用户会话 bean,并且用户只能在屏幕上查看一堆 java 异常。他们解决此问题的唯一方法是重新启动浏览器。
相反,我希望应用程序能够优雅地处理这样的事情...基本上能够捕获任何这些未捕获的异常并显示错误消息(和/或可能包含一个允许用户注销/登录的链接,这样他们就不会不必重新启动浏览器)。
JSF 有办法轻松做到这一点吗?如果没有,有人有解决方案吗?
If my JSF applications, I'll sometimes come across a bug that, for example, corrupts a user session bean somewhere and the user is stuck looking @ a bunch of java exception gobbly-gook on their screen. The only way they can fix this is to restart their browser.
Instead, I would like the application to handle something like this gracefully...basically by being able to catch any of these uncaught exceptions and display an error message (and or possibly contain a link to allow the user to logout/login so they don't have to restart their browser).
Is there a way for JSF to do this easily? If not, does anyone have a solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需创建一个自定义错误页面并在
web.xml
的
中定义其位置即可。例如,
您可以自由地使其看起来像您想要的那样。
You can just create a custom error page and define its location in
<error-page>
inweb.xml
.E.g.
You've all freedom to make it look like the way you want.
瞄准 BalusC 提出的解决方案,因为从长远来看是更容易维护的,否则你可以尝试这样的事情(实际上我已经通过定义自己的自定义视图处理程序来进行异常处理做了类似的事情): 自定义 JSF/Facelet 异常处理
Aim for the solution proposed by BalusC since in the long term is the easier thing to maintain, otherwise you could try something like this (actually I already did something similar by defining my own custom view handler for exception handling): Custom JSF/Facelet Exception Handling