about no-attr in session, maybe this help. Maybe you could try to put your listener at very begin of the web.xml
dennis ( 2013-01-24 02:30:01 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi guys
I have a table "UserLoginHistory" in my Sql Database. When the user logs in to the web app it saves the log-in date for that user in the table. When the user clicks on the "Logout" button in the webapp, it fetches that same record and sets the log-out date and time.
My problem is i need to do the same thing for when the user logs out, but when the session expires(30 minutes). How would i call a method in one of my controller classes to update the database when the session expires.
Any help is appreciated. Thanks!
When user click logout directly, the event is triggered by the user action, so you can do the db-log by controller.
If you intent to listen to session-timeout, you have to write a HttpSessionListener
and access the database in the listener lifecycle method.
about no-attr in session, maybe this help. Maybe you could try to put your listener at very begin of the web.xml
dennis ( 2013-01-24 02:30:01 +0800 )editWhat you want to use here is a class that implements HttpSessionBindingListener.( For example maybe your User class have it implement the interface.)
Assuming your user was put into the session, when it's about to be removed from the session because the session is going to expire the valueUnbound(HttpSessionBindingEvent event) is called, so you would implement this method in your User class.
and you'd do something like ...
public void valueUnbound(HttpSessionBindingEvent event) {
User user = (User)event.getValue();
someServiceClass.recordTheUserWhosSessionExpired(user);
}
Another option is to keep your own copy of Sessions (a minimalistic copy), and have a thread that periodically checks it against the live sessions in the Sessions object that the ZK framework is managing. Any session that is not found, you can assume it expired or was abandoned, and record it as such. In this way, you don't have to worry about catching an expired session before ZK wipes out its session data.
I would also wire in a Runtime.addShutdownHook to make sure you run the sessions check before the container shuts down.
Ron
Asked: 2013-01-23 09:08:12 +0800
Seen: 96 times
Last updated: Jan 24 '13