Bo Xu wrote:
> [EMAIL PROTECTED] wrote:
>
> > When a Tomcat session times out does it send you to a preset error page?
> > What is the mechanism there?
> > What is the best way to handle timed out users?
>
> Hi :-) I suggest you make a object witch implements
> javax.servlet.http.HttpSessionBindingListener, and put object into a session
>
> by "setAttibute(...)", then:
> - when that object is "bounded" into session, "valueBound(...) will be
> called
> by container
>
> - when the session is timeout/inValidate(...), that object will be
> "unbounded",
> then "valueUnbound(...) will be called by container
>
> the following is a sample code from Servlet-List:
>
> class CleanUp implements HttpSessionBindingListener{
> private String name;
>
> public CleanUp(String name){
> this.name = name;
> }
>
> public void valueBound(HttpSessionBindingEvent evt){
> System.out.println("in CleanUp, valueBound..., name="+name);
> }
>
> public void valueUnbound(HttpSessionBindingEvent evt){
> System.out.println("in CleanUp, valueUnBound..., name="+name);
> }
> }
>
> in MyServlet:
> ...
> session.setAttribute( "Cleaner", new CleanUp(...) );
> ...
>
> *
> - if CleanUp.class is in WEB-INF/classes or in a jar file in WEB-INF/lib,
> it will be loaded by WebappClassloader
> - if CleanUp.class is in TOMCAT_HOME/classes or in a jar file in
> TOMCAT_HOME/lib, it will be loaded by SharedClassloader
>
> Bo
> June 22, 2001
Hi :-) I forgot one of another ways: javax.servlet.http.HttpSessionListener
it is a new Interface in Servlet spec2.3 for "Lifecycle events" which includes:
- public void sessionCreated(HttpSessionEvent se)
- public void sessionDestroyed(HttpSessionEvent se)
please see:
http://www.javaworld.com/javaworld/jw-01-2001/jw-0126-servletapi_p.html
have a nice day :-)
Bo
June 23, 2001