Dustin Sun
Dustin Sun

Reputation: 5532

Session-timeout configuration doesn't work?

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?

Upvotes: 2

Views: 5613

Answers (1)

BalusC
BalusC

Reputation: 1109570

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.

Upvotes: 6

Related Questions