Nauman Rafique wrote:

> Hi,
> I am trying to keep a usage record for each user who connects to my servlet.
> So I need some function which is called when a session is destroyed.....so
> that i can record the creation and termination time for a session.........
> Can any body tell me if there is some function like that or how to keep the
> usage record???
>
> Thanks in advance
> [...]

Hi :-)  from a email in Servlet-List, I suggest you try the following:

 - when a object implementing javax.servlet.http.HttpSessionBindingListener
    is bening added to a HttpSession, the method valueBound() will be
    invoked; and if this object is being removed from this HttpSession,
    the method valueUnbound() will be invoked.
  - so if we are sure that we don't add/removed this object by ourself,  But
    the valueBound()/valueUnbound() is/are still invoked, then we can believe
    that the reason is: this Httpsession is caeated/invalidated (or "timeout")
  - so in this case, I think you can use valueBound()/valueUnbound() to
      record the creation and termination time for a session. the following
      is a sample code I study from that email:

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

class Recoder implements HttpSessionBindingListener{
   public void valueBound(HttpSessionBindingEvent evt){
      System.out.println("in CleanUp, valueBound...");
   }

   public void valueUnbound(HttpSessionBindingEvent evt){
      System.out.println("in CleanUp, valueUnBound...");
   }
}


and you can use this Recoder class in your Servlet, for example:
      ...
      session=req.getSession(true);
      ...
      session.setAttribute(  "Recoder", new Recoder() );
      ...




Bo
Mar11, 2001

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to