如何处理 JSF 2 中的会话过期和 ViewExpiredException?
考虑以下场景。 在会话超时(过期)后,我单击 JSF 表单的提交按钮。 浏览器显示一些异常消息:
ViewExpiredException:无法恢复视图上下文
我想要做的是,在会话过期后自动重定向到网站的主页。这样做的机制是什么?任何帮助将不胜感激。
Consider the following scenario.
I am clicking the submit button of a JSF form, after the session has timed out(expired).
The browser displays some exception message:
ViewExpiredException: view context could not be restored
What I want to do is, to automatically redirect to the homepage of the website after the session has expired. What is the mechanism to do this? Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在 HTTP 会话已过期且 JSF 视图状态保存方法设置为
server
时用户在页面上调用同步 POST 请求时处理异常,请添加
到web.xml
捕获 JSFViewExpiredException
并显示主页。要处理异步(ajax)请求的异常,您需要实现一个自定义的 ExceptionHandler ,如 JSF/PrimeFaces ajax 请求上的会话超时和 ViewExpiredException 处理
另请参阅:
To handle the exception whenever the user invokes a synchronous POST request on a page while the HTTP session has been expired and the JSF view state saving method is set to
server
, add an<error-page>
to theweb.xml
which catches the JSFViewExpiredException
and shows the home page.To handle the exception on asynchronous (ajax) requests as well, you need to implement a custom
ExceptionHandler
as answered in Session timeout and ViewExpiredException handling on JSF/PrimeFaces ajax requestSee also: