When sessions is timeout , a new javascript window appears on screen?

Hi dear experts,
I am using tomcat 5.0.x and developing web application with jsp. When my client session is time out , I want to show popup window saying that "your session is dead because you didnt do anything for 15 minutes".
How can i do this ?  to know when session it time out i have to write a listener  but how can i popup a windows through servlet or jsp when session is time out?
Who is Participating?
TimYatesConnect With a Mentor Commented:
This will have to be on a page refresh, you cannot just pop windows up without the client requesting a page

Also, remember that new browsers block popups (IE 6, SP2 -- Firefox -- Opera), so most people won't see your popup anyway...

When the session times out, it is destroyed, so you will have to check for a value in the current session.  If the value is not there, tell them they have to log in (and that it may be because they timed out), then send them to the login page (you can store the current page in the session, so they can automatically return to their current page after a successful login)

ramazanyichConnect With a Mentor Commented:
You can't initiate any client action from server. So you need add  javascript function (eg. name it auth) into all your pages which will do some action after some time.
and call it using <body onLoad="setTimeout(function,15*60*1000)">
15 can be replaced by your sessioin timeout.

in function auth you can perform some checks and open new window.
Ooooh!  Nice :-)

Of course, if you change your timeout in web.xml, you will need to change all of your jsp's too ;-)
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

You can use session.getMaxInactiveInterval() API call to set timeout value dynamically in your HTML output
elmakargeAuthor Commented:
Why do i have to change all jsp files   Cant i pass  session timeout value from  web.xml to javascript by a variable ?  I know that we  reach paramter values in web.xml  from jsp files?
Am i wrong ?
> Cant i pass  session timeout value from  web.xml to javascript by a variable ?

ramazanyich just showed you how :-)

<body onLoad="setTimeout( function, <%= session.getMaxInactiveInterval() %> * 60 * 1000 )">
NOTE: getMaxInactiveInterval() returns timeout in seconds. So you should remove *60. Modified string will look like:
<body onLoad="setTimeout( function, <%= session.getMaxInactiveInterval() %>  * 1000 )">
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.