jsf - 如果jsf应用程序中发生 session 超时,如何重定向到索引页面

标签 jsf

我正在使用 JSF RI 1.1。如果 session 超时如何重定向到索引页面?

最佳答案

有两种方法可以组合使用:

  1. 利用 <meta>刷新 HTML 中的 header <head>元素与 HttpSession#getMaxInactiveInterval() 结合它返回 session 尚未存活的剩余秒数。

    <meta http-equiv="refresh" content="${pageContext.session.maxInactiveInterval};url=index.jsf">
    

    此方法会自动将页面重定向到给定的 url当 session 过期时。

  2. 捕获 ViewExpiredException web.xml :

    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/index.jsf</location>
    </error-page>
    

    此方法会自动将请求转发到给定的 <location>POST当 session 过期时,请求已被触发( h:commandButtonh:commandLink 等)。

请注意,我个人更喜欢中间的“ session 过期”警告页面或警报以避免“wtf?”体验,从而提高用户体验。更重要的是,当客户端通过监听 click 显示事件时,我宁愿每分钟触发一次 ajaxical 轮询。和keypress ,以便 session 的生命周期可以推迟更多。

关于jsf - 如果jsf应用程序中发生 session 超时,如何重定向到索引页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2543094/

相关文章:

jquery - Ajax 提交 - 选择并聚焦字段并出现验证错误

jquery - 自动调整大小在 primefaces 5.3.6 的输入文本区域不起作用

ajax - gmap PrimeFaces p :ajax

JSF 2.2 导航规则未触发

java - 托管 bean 属性值未设置为 null

jsf - 自动计算数据表页脚中具有数字数据的列的总和

jsf - p :dataTable rowEdit are not available in listener method as they are being overwritten by existing data from database 中的编辑/更新值

jsf - 在 URL 中使用 & 会导致 XML 错误 : The reference to entity "foo" must end with the ';' delimiter

javaee IsUserInRole 总是返回 false jsf

css - 识别当前选定列表项的 Facelets 策略