问题描述
请考虑以下情形.会话超时(过期)后,我单击JSF表单的提交按钮.浏览器显示一些异常消息:
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:
我想做的是,在会话期满后自动重定向到网站的主页.这样做的机制是什么?任何帮助将不胜感激.
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.
推荐答案
在HTTP会话已过期且JSF视图状态保存方法设置为,将<error-page>
添加到web.xml
,以捕获JSF 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 the web.xml
which catches the JSF ViewExpiredException
and shows the home page.
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/home.xhtml</location>
</error-page>
要同时处理异步(ajax)请求上的异常,您需要实现自定义ExceptionHandler
,如
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 request
这篇关于如何在JSF 2中处理会话到期和ViewExpiredException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!