Determining when session expires

November 30

I want to be able to track the amount of time that the user spends on my site. I am going to insert a record into a database when the user logs on. I also want to insert a record when the user's session expires either from timing out or closing the browser window or leaving my site. Is it possible to determine when a user's session ends, particularly when it ends via the last two ways.



First, you can use a javax.servlet.http.HttpSessionBindingListener object put into the session as an attribute and implement the valueUnbound() method to do the database update. This will be called when you invalidate the session (unless you remove the attribute manually first).
So the problem is when will the session be invalidated..... There are really 4 things you are looking for:
1) session times out
2) user logs out (assuming you provide a log out link that invalidates the session)
3) browser closes
4) user leaves site (I assume you mean just goes to some other site in the same browser window)
1 and 2 are okay, cuz it invalidates the session and calls the valueUnbound method of the object you create as mentioned above.
For 3 and 4, you can do this in one of 2 ways:
A) Use frames in your web pages and in the top window, you can have a Javascript call some logout page. However, I'm not convinced that this will work in all situations.
B) Have an applet in the pages that does something to keep the connection alive. This requires an applet and a JVM in the client to run it. Probably not a good thing to rely on for public sites.
So really, there is no foolproof or simple way to handle 3 and 4, except to use session timeouts and rely on that.

View 2 Replies


  1. 1020dead soulision
  2. how to enable mosh in Cisco routers
  3. ifroget my icloud id n pasword
  4. add puffin to ipad ios 5.1
  5. Primary BT ID
  7. mass approval fk09
  8. PTI7
  9. gladpng
  10. tongueri1
Copyrights 2019 Fcffair BigData Resource, All rights reserved