Detecting the end of an HttpSession

Discussions

Web tier: servlets, JSP, Web frameworks: Detecting the end of an HttpSession

  1. Detecting the end of an HttpSession (5 messages)

    I am using a an HttpSessionListener to detect the start and end of HTTP Sessions.

    The issue I have is that I can only detect the end of the session when I programmatically invoke the invalidate() method,the session timesout or I shutdown the server.This will trigger the sessionDestroyed() method of the listener.

    However I also need the listener to be fired when the user closes their browser without invoking the servlet that invalidates the session.(I'm sure we've all killed a browser before without properly logging out).This needs to be fired immediately as it is for a connection counter, therefore setting session timeout values wouldn't suffice.

    Stateless Http really gets up my nose sometimes!! Any suggestions are most welcome.
  2. You can define onUnload event with some JavaScript code,
    where you will be able to call some URL ...

    Dmitry
    Coldbeans
  3. Unfortunately, unload is not going to work because the user is going to loose his session every time he clicks on any link which gets a new page (because of unload event of the old page). At the most the user will see the page that is displayed right after login. Any clicks on this page will trigger a call to session invalidate function, and, if the application is done right, he will/should again see the login page because access to the next page will blocked beacuse of invalid session.
  4. Use SessionListener: see Servlet 2.3 specs.
  5. Use SessionListener: see Servlet 2.3 specs.
  6. Use SessionListener: see Servlet 2.3 specs.