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).
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
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.