wich listener? context or session?
im developing a web app where a loging process is needed, i store a user javaBean at session scope
my troubles are when finalizing the session, i use session.invalidate() in my logout page and it's fine but will the sessionDestroyed method in the HttpSessionListener will be called when the user just close the window broser? shall i use Session or context listener?
thanks for your help
[407 byte] By [
danihmoran] at [2007-9-30 19:26:29]

>i use
> session.invalidate() in my logout page and it's fine
> but will the sessionDestroyed method in the
> HttpSessionListener will be called when the user just
> close the window broser?
Typically the server will never know if the browser was closed abruptly. So sessionExpired method of the session listener will only be called when the session times out. However, you can detect the window close event via javascript on the client side and relay the info to the server where you invalidate the session. A typical workaround involves submitting a hidden frame which submits to your logout page.
import javax.servlet.*;
import javax.http.servlet.*;
//get it? Beans are wrapped in a burrito?
//bean burrito? I kill myself! :)
public class MyBurrito implements HttpSessionBindingListener
{
public class MyBeanClass refriedBeans = null;
public MyBurrito(MyBeanClass r)
{
this.refriedBeans = r;
}
public void valueBound(HttpSessionBindingEvent hsbe)
{
//whatever
}
public void valueUnbound(HttpSessionBindingEvent hsbe)
{
//this method will be called by the container
//immediately after the session is invalidated.
//do some logging here.
//Modify the next line, appropriately.
log("HERE IS SOME INFORMATION TO BE WRITTEN TO THE LOG.");
}
}
In your login servlet's doPost(),put the Burrito in session.
public void doPost(HttpServletRequest request, HttpServletReponse response)
{
// ...
MyBurrito burrito = new MyBurrito(anInstanceOfMyBeanClass);
request.getSesion().setAttribute();
// ...
}