会话超时配置不起作用?

发布于 2024-08-28 22:00:58 字数 562 浏览 5 评论 0原文

web.xml 中,我有这个

 <session-config>
   <session-timeout>2</session-timeout>
 </session-config>

 <listener>
  <listener-class>myapplication.SessionListener</listener-class>
 </listener>

SessionListener.java 中,我有

public void sessionDestroyed (HttpSessionEvent event){    
   System.out.println("Visitor Removed!!");
}

但似乎 System.out.println("Visitor Removed!!") 从未被执行过。我是 Tomcat 6 和 JSP 的新手。请问有什么建议吗?

In web.xml I have this

 <session-config>
   <session-timeout>2</session-timeout>
 </session-config>

 <listener>
  <listener-class>myapplication.SessionListener</listener-class>
 </listener>

In the SessionListener.java I have

public void sessionDestroyed (HttpSessionEvent event){    
   System.out.println("Visitor Removed!!");
}

But it seems System.out.println("Visitor Removed!!") has never been executed. I am new to Tomcat 6 and JSP. Any suggestion please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望喜 2024-09-04 22:00:58

这至少可能有 3 个原因:

  1. 会话从未创建。还要监听 sessionCreated()
  2. 你有点不耐烦了。会话销毁是惰性且间歇性发生的。它不会立即发生。如果您在同一会话中触发请求,而该会话已过期,则将调用sessionDestroyed()。或者,如果您有更多的耐心,服务器将运行其低优先级计时器作业来获取所有过期的会话。
  3. 您没有像您认为的那样在类路径中使用 myapplication.SessionListener 类,也许类路径中实际没有 sysout 行。

This can have at least 3 causes:

  1. The session has never been created. Listen on sessionCreated() as well.
  2. You are a bit impatient. Session destroy happens lazily and at intervals. It does not happen immediately. If you fire a new request in the same session while it has been expired, then sessionDestroyed() will be called. Or if you have a bit more patience, the server will run its low-prio timer job to reap all expired sessions.
  3. You are not using the myapplication.SessionListener class in the classpath as you think you're using, maybe the one actually in the classpath doesn't have a sysout line.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文