有什么方法可以预测会话超时吗?
有没有办法“捕获”会话超时事件,以便在 HttpSession 失效之前检索数据?
我们正在实现 Filter 接口,并且在 doFilter 方法中,当会话超时时,我们在登录时存储在会话对象中的用户为 null。
提前致谢。
Is there a way to "catch" the session timeout event, so as to retrieve data from HttpSession before its invalidated ?
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.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该能够注册 HttpSessionListener 对于您的网络应用程序,它将允许您在会话被销毁时收到通知。
它有两个回调方法:
public void sessionCreated(HttpSessionEvent se)
public void sessionDestroyed(HttpSessionEvent se)
HttpSessionEvent
类有一个getSession
方法应该可以让您获取受影响的会话。侦听器类在
web.xml
中注册You should be able to register an HttpSessionListener for your webapp that will allow you to get notified when a Session is destroyed.
It has two callback methods:
public void sessionCreated(HttpSessionEvent se)
public void sessionDestroyed(HttpSessionEvent se)
The
HttpSessionEvent
class has agetSession
method that should let you get the affected session.The listener class is registered in the
web.xml
让用户对象实现 HttpSessionBindingListener,然后它可以自己查看何时添加到会话或从会话中删除。
Have the user object implement HttpSessionBindingListener, then it can see for itself when it is added to or removed from the session.
您始终可以添加一段 JSP 来检查您的会话是否仍然处于活动状态或有效 - 基本上检查会话变量是否存在 (!=null),如果不存在 - 将用户重定向到另一个页面 -
希望这有帮助
标记
来源:http://www.coderanch.com/t/ 279538/JSP/java/jsp-会话超时
You can always ad a piece of JSP that will check to see if your session is still active or valid - basically check to see if a session var exists (!=null) and if it doesn't - redirect the user to another page -
Hope this helps
Mark
Source : http://www.coderanch.com/t/279538/JSP/java/jsp-session-timeout