SessionListener is what you want.
Here's an example from one of my apps (condensed for space)... it is used
to delete a temporary PDF that may have been generated for the user when
they log off:
import company.app.User;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class MySessionListener implements HttpSessionListener {
public synchronized void sessionCreated(HttpSessionEvent se) {
}
public synchronized void sessionDestroyed(HttpSessionEvent se) {
HttpSession sess = se.getSession();
User user = (User)sess.getAttribute("user");
String userID = user.getUserID();
AppHelpers.deletePDF(userID);
}
}
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Mon, July 25, 2005 12:47 pm, Daniel Perry said:
> I have an app where i need to record key user stats, which are updated by
> certain struts actions. The problem is that i want to keep these in the
> session, and then only save them to the database when the session is
> either
> invalidated through logout, or when it times out and is removed by the
> server. It doesnt matter if some stats are lost through crashes, server
> restarts, etc.
>
> I cant see an obvious way to find out when sessions are destroyed.
>
> Would it be possible to have a class called stats, which is put into the
> session, and override the finalize method, so that this writes to the
> database the calls super.finalize? Would this work?
>
> If i make this serializable, what happens if the server decides to remove
> this session after writing to disk - does it just delete the file, or does
> it reserialize it and call finalize?
>
> Thanks,
>
> Daniel.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]