tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Manu KY <>
Subject Session Lifecycle event listener problem
Date Fri, 28 Sep 2001 15:13:17 GMT
Hello all,
this is my first post to the list and i apologise for the long message.
i have written a bean which implements HttpSessionListener interface.
Then i added the listener entry in web.xml file.

but,tomcat doesnt create the listener instance before serving the first 
request to the web-app as i dont see the message in the console.

please help.
am i missing something?

here's my code:

package org.manu.utils;

import javax.servlet.http.*;
import java.util.*;

public class SessionLogger implements HttpSessionListener,Serializable{
  private Hashtable sessionsData = new Hashtable();
  private static int num = 0;

  public SessionLogger(){System.out.println("SessionLogger created");}

  public Enumeration getSessions(){
   return sessionsData.keys();
  public void sessionCreated(HttpSessionEvent sEvent){
   sessionsData.put(sEvent.getSession().getId(),new Integer(++num));
   System.out.println("Session created : " + sEvent.getSession().getId());
  public void sessionDestroyed(HttpSessionEvent sEvent){

  private void checkTimeOutOrInvalidated(HttpSession session){
   long creationTime = session.getCreationTime();
   long lastAccessedTime = session.getLastAccessedTime();

   int maxInactiveInterval = session.getMaxInactiveInterval();

   if((lastAccessedTime - creationTime)*1000 >= maxInactiveInterval){
    System.out.println("Session invalidated due to time out");
    System.out.println("Session invalidated due to invalidate()");


thanks for your time.

Do You Yahoo!?
Get your free address at

View raw message