有什么方法可以预测会话超时? [英] Any way to anticipate session timeout?

查看:144
本文介绍了有什么方法可以预测会话超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法捕获会话超时事件,以便在无效之前从HttpSession中检索数据?

Is there a way to "catch" the session timeout event, so as to retrieve data from HttpSession before its invalidated ?

我们正在实现过滤器接口,并且在doFilter方法中,当会话超时时,我们在登录时存储在会话对象中的用户为空。

We're implementing the Filter Interface, and in the doFilter method, the user we stored in the session object at login is null when session times out.

提前致谢。

推荐答案

您应该能够注册一个 HttpSessionListener ,可以让你在会话被销毁时得到通知。

You should be able to register an HttpSessionListener for your webapp that will allow you to get notified when a Session is destroyed.

它有两种回调方法:


  • public void sessionCreated(HttpSessionEvent se)

  • public void sessionDestroyed(HttpSessionEvent se)

  • public void sessionCreated(HttpSessionEvent se)
  • public void sessionDestroyed(HttpSessionEvent se)

HttpSessionEvent 类有一个 getSession 方法,可以让你获得受影响的se ssion。

The HttpSessionEvent class has a getSession method that should let you get the affected session.

监听器类在 web.xml中注册

<listener>
  <description>My Session Listener</description>
  <listener-class>
    my.package.MySessionListener
  </listener-class>
</listener>

这篇关于有什么方法可以预测会话超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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