Samuel Arnod-Prin wrote:
> Hello,
>
> I've had to modify tomcat because I didn't know if there was a solution,
>
> I would like to be warned when a HttpSession expires and becomes
> invalidated.
> Is there a way to do this ?
> Or should I keep my modification in tomcat class to the expire() method
> ?
>
> thank you
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 removed this object by ourself, But
the valueUnbound() is still invoked, then we can believe that the
reason is: this Httpsession is invalidated/expired
- so in this case, I think you can use valueUnbound(), the following
is a sample code I study from that email:
import javax.servlet.http.*;
class Recoder implements HttpSessionBindingListener{
public void valueBound(HttpSessionBindingEvent evt){
System.out.println("in Recoder, valueBound...");
}
public void valueUnbound(HttpSessionBindingEvent evt){
System.out.println("in Recoder, valueUnBound...");
}
}
and you can use this Recoder class in your Servlet, for example:
...
session=req.getSession(true);
session.setAttribute( "Recoder", new Recoder() );
...
Bo
Mar19, 2001