tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Manu KY <manu_...@yahoo.com>
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.*;
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


Mime
View raw message