如果jsf应用程序中发生会话超时,如何重定向到索引页 [英] How to redirect to index page if session time out happened in jsf application
问题描述
我正在使用JSF RI 1.1.如果会话超时,如何重定向到索引页面?
I am using JSF RI 1.1. How to redirect to index page if session time out happens?
推荐答案
有两种可以组合的方式:
There are two ways which can be combinied:
Make use of the
<meta>
refresh header in the HTML<head>
element in combination withHttpSession#getMaxInactiveInterval()
which returns the remnant of seconds the session has yet to live.
<meta http-equiv="refresh" content="${pageContext.session.maxInactiveInterval};url=index.jsf">
这种方法将在会话期满后自动将页面重定向到给定的url
.
This approach will automatically redirect the page to the given url
when the session expires.
捕获 ViewExpiredException
在web.xml
中:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/index.jsf</location>
</error-page>
当会话到期时触发了POST
请求(h:commandButton
,h:commandLink
等)时,此方法将自动将请求转发到给定的<location>
.
This approach will automatically forward the request to the given <location>
when a POST
request has been fired (h:commandButton
, h:commandLink
, etc) while the session is expired.
请注意,我个人希望使用中间的会话已过期"警告页面或警报以避免"wtf?".体验,从而改善用户体验.更甚者,当客户通过监听click
和keypress
来显示活动时,我宁愿每分钟触发一次ajaxical民意测验,以使会话的生存期可以更长.
Note that I personally would prefer an intermediate "Session Expired" warning page or alert to avoid "wtf?" experiences and thus improve the user experience. Even more, I would as well prefer firing an ajaxical poll every minute when the client has shown activity by listening on click
and keypress
, so that the session's lifetime can be postponed more.
这篇关于如果jsf应用程序中发生会话超时,如何重定向到索引页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!