java在会话超时侦听器中区分超时破坏的会话和手动破坏的会话
我想实现一个在会话过期时调用的侦听器,我发现我可以创建一个实现接口HttpSessionListener
的侦听器,并重写方法sessionDestroyed
public class SessionListener implements HttpSessionListener {
@Override
public void sessionCreated(HttpSessionEvent sessionEvent) {
// TODO Auto-generated method stub
}
@Override
public void sessionDestroyed(HttpSessionEvent sessionEvent) {
// TODO Auto-generated method stub
}
}
但问题是每次会话被销毁时(例如登录和注销)都会调用此方法,因此如何知道会话在会话过期后被销毁,或者是否存在除HttpSessionListener
之外的其他解决方案
PS:我在应用程序中使用Spring框架
# 1 楼答案
也许你可以试着这样猜:
可能的超时=(CurrentTime-LastAccessedTime)>;=MaxVeInterval
输出如下:
我观察到,不一定会立即检测到超时。似乎有一个线程定期检查会话超时。此外,每个请求都有一个检查