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.pr开发者_如何学编程intln("Visitor Removed!!")
has never been executed. I am new to Tomcat 6 and JSP. Any suggestion please?
This can have at least 3 causes:
- The session has never been created. Listen on
sessionCreated()
as well. - 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. - 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.
精彩评论