File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes regarding session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "regarding session" Watch "regarding session" New topic
Author

regarding session

krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
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


have a great day,
krishna prasad
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
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


Java Resources at www.wbrogden.com
Sanesh Fernando
Greenhorn

Joined: Sep 03, 2006
Posts: 1
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

Joined: Jul 25, 2006
Posts: 158
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding session
 
Similar Threads
agents as servlets
Chapter 6(Session Management) notes (HFSJ) for revision
destroy sessionContext from EJB?
User who is logged in simultaneously from different browser ... how to forcely logout the first user
Tomcat - sessions do not expire