I'm storing session data in my application. I need to know how I can insert that data into a db at the end of a session -- both by explicitly killing the session (ie -- logout) or by session timeout. I am running Tomcat 3.2.2 on Apache w/ Oracle 8.1.7 Thanks for your help.
implement the interface javax.servlet.http.HttpSessionBindingListener to bind all ur values to session. When the sesison times out or when it is invalidated (on clicking a 'logout' button, invalidate the session), it invokes sessionUnbound() on all the listeners. U can put in code for insertion into database in sessionUnbound() method then.
It might make more sense to bind a single listener and have it be responsible for persisting all the session data (as opposed to having each data object be responsible for persisting itself).
Joined: Sep 07, 2001
Thanks for the replies. I'm still having a bit of a time trying to figure this out. Could someone reply with some sample code of how I might do this? Thanks.
Joined: Jun 07, 2000
If the object that u store in session is SessionBoundObject, when this obj is added to session by using : session.putValue("name", obj); it executes the valueBound() method. And when session is destroyed, the valueUnbound method is called. So whatever u need to do before destroying this object (like insert into database) should be done in the valueUnbound() method.