• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing to Database when User leaves the site

 
Zubair Ahmed
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am maintaining my user's UserIDs in Sessions, once the user signs in using the Sign In page his/her user id gets stored in the Session and then on every page I check the session for a value to make sure that user has properly signed in. There is also a Sign Out btn to sign out. When the user properly signs out using the sign out btn I write some information to the database. The issue comes when the user improperly signs out by closing the browser window or the user may leave the window inactive for a long time which will result in session expiration, in both circumstances I want to be able to write some info to the database.
I suppose in ASP you can achieve this by triggering the OnSession_End (or something like that) event in global.asa file, is there a similar solution for JSP?
TIA
 
Tieyi Guo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should use "HttpSessionBindingListener" to solve this problem.
The quote below is from Java API:
"When an application stores an object in or removes an object from a session, the session checks whether the object implements HttpSessionBindingListener. If it does, the servlet notifies the object that it has been bound to or unbound from the session."
Hope this helps.
Tieyi
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out this thread in the Servlet forum -- it addresses basically the same issue.

------------------
- Jessica Bradley
HP Bluestone
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!