session variables timing out


My session variables seem to time out after a certain period of time, is there a way to set the time they can last?
How to redirect a user to jsp page when the session has timed out?
SuAeEAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
you can't do that the session time out occurs on the server, the browser know nothing about it.
0
 
objectsCommented:
your container will probably have an option to set the timeout, check its doco.
0
 
SuAeEAuthor Commented:

Im kind of new to this, could you give me instructions to check this plz
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
objectsCommented:
what container are you using?
0
 
SuAeEAuthor Commented:

What is a container? im using tomcat 4.1
0
 
objectsCommented:
tomcat is a container :)

you can set the timeout in tomcats web.xml file:

<session-config>
   <session-timeout>60</session-timeout>
</session-config>
0
 
SuAeEAuthor Commented:

Very good, and how about redirecting when to a page when the session times out?
0
 
objectsCommented:
if the session has timed out, then a new empty session will be created so you can test that.
0
 
SuAeEAuthor Commented:
What will the name of the session be? I mean something like?:

 if( session.getAttribute( "timmedout" ) == null )
    response.sendRedirect( "notloggedin.jsp" ) ;
0
 
objectsCommented:
no the session will be empty same as when they first load a page, so check for a variable that your code adds to it.
0
 
SuAeEAuthor Commented:

Im lost, i dont know what you mean, could you post code to explain it plz?
0
 
objectsCommented:
i don't know how you are using the session so can't help with specific code.
But the redirect will be exactly the same as if the user was trying to load the page for the first time.
Do you currently redirect in this case?
0
 
SuAeEAuthor Commented:

>> so check for a variable that your code adds to it.

Could you explain this more clearly plz


0
 
objectsCommented:
what happens when a person currently loads this page for the first time?

what do you currently use the session for?
0
 
SuAeEAuthor Commented:

Im setting many session variable throughout the web app. The first session that is set is a "loggedin" session. Is this what you mean?
0
 
objectsCommented:
yes so check if "loggedin" has been set in session.
0
 
SuAeEAuthor Commented:

Im checking for that already:

 if( session.getAttribute( "loggedin" ) == null )
    response.sendRedirect( "notloggedin.jsp" ) ;

Is this what you mean by set in session?
0
 
SuAeEAuthor Commented:

I want to check if the session timer limit has been reached and redirect aotomatically if it has
0
 
objectsCommented:
yes that is correct, so you don't need to add anything as you are already handling it.
0
 
SuAeEAuthor Commented:

Yes but what I ideally want is that if a user leaves his machine and the session variable times out there is automatic redirection to a "notlogged" page.
0
 
SuAeEAuthor Commented:

I know sites that do this, they must be running some code that checks the session every so often? Anyway if thats the case I couldnt be bothered doing it, thanks for the help
0
 
objectsCommented:
only way i can think of to achieve it is to run a timer of some description on the client.
I doubt they actually check whether the session has actually timed out or not.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.