• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regarding session

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to find the time, in seconds, for which my client is active, and need to store the time in, time out in a databse table. Sessions are the obvious way to do it.
A session is destroyed, when it has reached it's time limit or the client chooses to end his session(logging off).
We can set timeouts in xml or in servlet. How can we handle explicit logging out performed by the client.
1. sholud we use a separate servlet to handle this, so that we can get the session associated with the client and call the invlaidate() method on that session object.
2. we have getCreationTime() to find the time when the session was created. is there a method to find the time when the session was destroyed? there won't be a session to call methods on when it has been destroyed, but i still have that doubt, is there a method?
can we use HttpSessionListener's sessionDestroyed(HSE e) method(create a Date and pass it to a model, to store the date in a database table).

Have nice day
krishna prasad
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about a class implementing HttpSessionBindingListener?
If you add an instance to the session when it is created, you can use the valueBound() method to record a start time and the valueUnbound method to record the end time. No matter how the session is invalidated, valueUnbound is guaranteed to be called.
Bill
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

Check this link for a full description of how to do this..

Detecting a HttpSession creation and HttpSession Time out
 
krishna prasad gunasekaran
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for your reply,
i have my first question unanswered. how to detect when the customers logout.
1.should we use a separate servlet to handle this, so that we can get the session associated with the client and call the invlaidate() method on that session object.
2.is there a way to get the details of the customer associated with that session. may be we can add attributes to that session that describe the customer. only then can i store the time-related details of the customer in a database table.
and what's the difference between valueBound() of HttpSessionBindingListener, and attributeAdded() of HttpSessionAttributeListener. Both are called when an attribute is added to a session. valueBound()is implemented by the attribute itself, and attributeAdded()is implemented by some other class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic