Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

session setMaxInactiveInterval() for each page?

843835Aug 22 2002 — edited Aug 23 2002
Hi, I'm wondering if when you set the max inactive interval to x seconds -- is that saying that each page is going to be given x seconds of max inactive time? Or does it mean the whole session from the first page that the user accesses to the last one?

Thanks so much!

Comments

843835
Hi,
Setting the session max inactive interval using session setMaxInactiveInterval() will set it for the whole session and not for a single page. Suppose you use:
HttpSession session = request.getSession(true);
session.setMaxInactiveInterval(100);

Then your session will timeout after 100 seconds till you validate the session again.

HTH
843835
Hi HTH,

Thank you so much for your reply. But how do you validate a session? I know there's a session.invalidate() but there doesn't seem to be a session.validate(). I want to reset the session time, so to speak, at each page. But I want to continue the session, not get a new session.

Thank you again!
843835
I suppose what I could do is set the max inactive interval to the current max inactive interval PLUS the time for the current page. Is there any other way?

Thanks!
843835
to see if a session is timed out you can do a few different things.

at the time the session is generated, you can store the session id in the session object as a string. then you can check for that on other pages. if you get a null returned on a session.getAttribute, then the session has timed out. if someone has a better way of doing this, let me know :) there also exists the method "isNew" but i have had limited success with this in detecting timed out sessions.

as for "resetting" the session TTL (time to live), this is done automatically each time a new page is loaded for that session. if you wish to change that TTL you need to call the function to set the time to a different amount.
843835
Jetsam,

I'm a bit confused. Please bear with me. Are you saying that you disagree with the first answer? That if I set the max inactive interval to 100 seconds, EACH page will have 100 seconds to live? I'm referring to this passage:
as for "resetting" the session TTL (time to live),
this is done automatically each time a new page is
loaded for that session.
Thanks!
843835
think of it this way... every time someone requests something from the server they have x amount of time to request something else before they are timed out. that amount of time is what you are setting. each time they ask for someone else, that time is reset back to its original setting and the clock starts ticking again.

now, each page you have could change that value if you wanted to.
843835
i said ...
that time is reset
back to its original setting and the clock starts
ticking again.
i dont want to confuse you. it is reset to the last value either you told it, or its default.

:)
843835
if im making no sense, which i probably am, i could explain better on AIM or MSN Messenger if you have either.
843835
think of it this way... every time someone requests
something from the server they have x amount of time
to request something else before they are timed out.
that amount of time is what you are setting. each
time they ask for someone else, that time is reset
back to its original setting and the clock starts
ticking again.
Ah. Ok. This is what I believed. I just wanted to make sure. Pheew! So, ok, I have a form. When I press submit, that next page restart the clock, yes?
now, each page you have could change that value if you
wanted to.
Yes, this part I understand. :)

Thank you so much!
843835
sure. Pheew! So, ok, I have a form. When I press
submit, that next page restart the clock, yes?
yup. because you requested more data from the server, your time out period gets reset again and starts counting down.

843835
yup. because you requested more data from the server,
your time out period gets reset again and starts
counting down.
Thank you for confirming everything! Cheers!
1 - 11
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 20 2002
Added on Aug 22 2002
11 comments
679 views