views:

250

answers:

2

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?

+2  A: 

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.
BalusC
or 4. System.out does not output to where you think it does
matt b
Check the tomcat log under $TOMCAT_HOME/logs in either catalina.<date>.log or localhost.<date>.log
Chuk Lee
Thank you BalusC. It should be Cause 2: I was not patient.
David
You're welcome.
BalusC
A: 

Does you SessionListener class implement HttpSessionListener

Mihir Mathuria
It would have produced an error during startup. You would be blind if you missed that ;)
BalusC