You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Manu KY <ma...@yahoo.com> on 2001/09/28 17:13:17 UTC

Session Lifecycle event listener problem

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.*;
import java.io.*;


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){
   checkTimeOutOrInvalidated(sEvent.getSession());
   sessionsData.remove(sEvent.getSession().getId());
  }

  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");
   }else{
    System.out.println("Session invalidated due to invalidate()");
   }
  }

}

thanks for your time.
Manu


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com