如何在会话超时时调用sessionDestroyed [英] How to call sessionDestroyed when a session times out

查看:754
本文介绍了如何在会话超时时调用sessionDestroyed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JSP的新手。我在实现 HttpSessionListener 的类中使用以下代码,以便在会话超时时获取SESSION OUT:

I am new to JSP. I used the following code in a class that implements HttpSessionListener to get SESSION OUT when the session times out:

    public void sessionCreated(HttpSessionEvent arg0) {  
        System.out.print("SESSION Created");
    }

    public void sessionDestroyed(HttpSessionEvent arg0) {
        System.out.print("SESSION OUT");
    }

我设置在 web.xml

  <session-config>
     <session-timeout>1</session-timeout> 
  </session-config>

servlet等待超过两分钟,然后调用 sessionDestroyed

The servlet waits more than two minutes, then it calls sessionDestroyed.

超时后是否有办法强制 sessionDestroyed

Is there is a way to force sessionDestroyed when time out ?

提前致谢。

推荐答案


servlet等待更多超过两分钟,然后它调用sessionDestroyed。

The servlet waits more than two minutes, then it calls sessionDestroyed.

有超时时间强制sessionDestroyed的方法吗?

Is there is a way to force sessionDestroyed when time out ?

这是特定于实现的(取决于应用程序服务器)。有一个后台线程以定时间隔检查会话并收到所有过期的会话。这可能每分钟发生一次,但也可能每15分钟发生一次。如果您在相关会话已经超时但尚未收到请求时触发请求,也会立即收回它们。

This is implementation specific (application server dependent). There is a background thread which checks the sessions at timed intervals and reaps all the expired ones. This may occur every minute but can also be every 15 minutes. They will also be reaped immediately if you fire a request while the associated session has already been timed out but not reaped yet.

因此,如果您等一分钟并开火一个新的请求,然后它会立即收到。真的没有必要担心这一点。你不需要强迫它立即收获它们,这本来是一项昂贵的任务。你知道,这只是编程,而不是一些魔术;)

Thus if you for instance wait one minute and fire a new request, then it will be immediately reaped. There is really no need to worry about that. You don't need to force it to reap them immediately, that would have been an expensive task. You know, it's all just about programming, not about some magic ;)

这篇关于如何在会话超时时调用sessionDestroyed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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