如何优雅地处理 JSF 应用程序故障?

发布于 2024-09-26 12:59:17 字数 236 浏览 0 评论 0原文

如果是我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女情怀诗 2024-10-03 12:59:18

您只需创建一个自定义错误页面并在 web.xml 中定义其位置即可。

例如,

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error.jsp</location>
</error-page>

您可以自由地使其看起来像您想要的那样。

You can just create a custom error page and define its location in <error-page> in web.xml.

E.g.

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error.jsp</location>
</error-page>

You've all freedom to make it look like the way you want.

别理我 2024-10-03 12:59:18

瞄准 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文