如果jsf应用程序中发生会话超时,如何重定向到索引页 [英] How to redirect to index page if session time out happened in jsf application

查看:129
本文介绍了如果jsf应用程序中发生会话超时,如何重定向到索引页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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:

  1. 结合使用 http://java.sun.com/javaee/5/docs/api/javax/和

  1. Make use of the <meta> refresh header in the HTML <head> element in combination with HttpSession#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:commandButtonh: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?".体验,从而改善用户体验.更甚者,当客户通过监听clickkeypress来显示活动时,我宁愿每分钟触发一次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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆