Bal*_*usC 44
有两种方法可以组合:
利用<meta>
HTML <head>
元素中的刷新标头结合使用HttpSession#getMaxInactiveInterval()
它返回会话尚未生存的剩余秒数.
<meta http-equiv="refresh" content="${pageContext.session.maxInactiveInterval};url=index.jsf">
Run Code Online (Sandbox Code Playgroud)
url
会话到期时,此方法将自动将页面重定向到给定页面.
赶ViewExpiredException
在web.xml
:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/index.jsf</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
<location>
当会话过期时,当POST
请求被触发(,等)时h:commandButton
,此方法将自动将请求转发给给定h:commandLink
.
请注意,我个人更喜欢中间的"会话过期"警告页面或警告,以避免"wtf?" 体验,从而改善用户体验.更有甚者,我想也喜欢射击的ajaxical调查每分钟时,客户端通过监听显示活动click
和keypress
,使会议的寿命可以被推迟了.
JSF2:
<meta http-equiv="refresh" content="#{facesContext.externalContext.sessionMaxInactiveInterval};url=#{request.contextPath}/index.xhtml"/>
Run Code Online (Sandbox Code Playgroud)