• Post Reply Bookmark Topic Watch Topic
  • New Topic

Insert session data into a db at end of session

 
Brian E
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Brian E
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!