Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving data at the time of session timing out

 
Mrigasira Srinivas
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am working on a web-based application that has a series of forms that the user fills out. If the session were to time out, I need to save the data entered by the user before logging him/her out. Can anyone tell me how this can be done? Any kind of help in this regard - including source code - would be much appreciated.
Thanks
 
Val Pecaoco
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yamini,
You can have a JSP instantiating a JavaBean that is bound in the Session object. This JavaBean then implements the HttpSessionBindingListener interface, which means it will have a "valueUnbound()" method "...that is called when the instance is unbound, which typically happens when the session is invalidated because the user logged out or was inactive for too long..." (from Java Examples in a Nutshell, 2/e (p. 482) by David Flanagan) You can then have code under "valueUnbound()" that saves data to a file or database.
The above-mentioned book has a downloadable example zip file from the O'Reilly Web site, which includes an application utilizing HttpSessionBindingListener.
GL
Ex Animo Java!
-- Val
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic