Solved

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

Posted on 2004-08-25
9
323 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:elmakarge
  • 3
  • 3
9 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 63 total points
ID: 11900176
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)

Tim
0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 62 total points
ID: 11900204
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.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11900216
Ooooh!  Nice :-)

Of course, if you change your timeout in web.xml, you will need to change all of your jsp's too ;-)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 19

Expert Comment

by:ramazanyich
ID: 11900248
You can use session.getMaxInactiveInterval() API call to set timeout value dynamically in your HTML output
0
 

Author Comment

by:elmakarge
ID: 11900287
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 ?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11900310
> 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 )">
0
 
LVL 19

Expert Comment

by:ramazanyich
ID: 11900342
NOTE: getMaxInactiveInterval() returns timeout in seconds. So you should remove *60. Modified string will look like:
<body onLoad="setTimeout( function, <%= session.getMaxInactiveInterval() %>  * 1000 )">
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question