HttpSession expired vs. invalidated

C

christoph

Hi,

I have a session holding user data of an online survey. When the survey
is completed, all data is written to a result file. After that the
session is manually invalidated (servlet calling the invalidate
method).

If the respondent does not complete the interview the session times out
at some point. I would like to flush the data I have in the session so
far to a special result file.

Is there a way of reacting to session expiration (by the server) and
not to invalidation (by the servlet)?

Using HttpSessionListener.sessionDestroyed(HttpSessionEvent se) does
not work, because the data of HttpSessionEvent.getSession() is not
accessible any more when the event is fired. Furthermore the
HttpSessionEvent is fired when the session expires and when the session
is manually invalidated.

Does anyone have advice?

THX,

Chris
 
W

William Brogden

Hi,

I have a session holding user data of an online survey. When the survey
is completed, all data is written to a result file. After that the
session is manually invalidated (servlet calling the invalidate
method).

If the respondent does not complete the interview the session times out
at some point. I would like to flush the data I have in the session so
far to a special result file.

Is there a way of reacting to session expiration (by the server) and
not to invalidation (by the servlet)?

Using HttpSessionListener.sessionDestroyed(HttpSessionEvent se) does
not work, because the data of HttpSessionEvent.getSession() is not
accessible any more when the event is fired. Furthermore the
HttpSessionEvent is fired when the session expires and when the session
is manually invalidated.

The answer is simple, make your class that holds the survey
results implement HttpSessionBindingListener - each instance
will then be notified when it is being unbound from the session
and it can then save the data itself.

Bill
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top