File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Saving data at the time of session timing out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » JSP
Bookmark "Saving data at the time of session timing out" Watch "Saving data at the time of session timing out" New topic

Saving data at the time of session timing out

Mrigasira Srinivas

Joined: Feb 28, 2001
Posts: 17
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.
Val Pecaoco
Ranch Hand

Joined: Dec 05, 2001
Posts: 156
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.
Ex Animo Java!
-- Val

"Knowledge is power, but enthusiasm is the key." -- Lavern Barn
I agree. Here's the link:
subject: Saving data at the time of session timing out