Save Attributes on HttpSession timeout ?

J

joerg

Hi,

I've got a little problem with my webapplication:

I want to save some user preferences that are stored
to the user's HttpSession when the session times out.

When using an HttpSessionListener the Listener's
sessionDestroyed(HttpSessionEvent event)
method gets called when the session times out.
The problem: event.getSession() gives me the session,
but I cannot access any Attributes. This just gives me
an exception saying "Session already invalidated" or something.

Is there a way to save session Attributes when the session times out?

Thank you very much,

Joerg
 
M

Michael Borgwardt

joerg said:
Hi,

I've got a little problem with my webapplication:

I want to save some user preferences that are stored
to the user's HttpSession when the session times out.

When using an HttpSessionListener the Listener's
sessionDestroyed(HttpSessionEvent event)
method gets called when the session times out.
The problem: event.getSession() gives me the session,
but I cannot access any Attributes. This just gives me
an exception saying "Session already invalidated" or something.

Is there a way to save session Attributes when the session times out?

Have the attributes implement HttpSessionBindingListener, they
will then be notified when they are unbound from the session
before it is invalidated.

However, I think it's very questionable design to store something
in the HttpSession that is in fact intended to outlive the session.
 
J

joerg

Michael Borgwardt said:
Have the attributes implement HttpSessionBindingListener, they
will then be notified when they are unbound from the session
before it is invalidated.

However, I think it's very questionable design to store something
in the HttpSession that is in fact intended to outlive the session.


Thank you for the hint. It works that way.

I intend to use it this way:

Whenever a user changes some of the application's setting, these
changes are made to the settings stored in the user's session. As this
happens very often, I did't want to access the database every time the
user makes some
changes.
When the user closes the application (whether by logout or session
timeout),
the settings will be written to the database.

Joerg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top