aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Warning a user that something will timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Warning a user that something will timeout" Watch "Warning a user that something will timeout" New topic
Author

Warning a user that something will timeout

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I have been asked to quote for a change to an existing web application, and I'm wondering if anyone here has any bright ideas.
The background is a fairly clumsy multi-window JavaScript/JSP/Oracle application. In common with many of this sort of application, the "session" mechanism has a timeout. After 30 minutes or so of inactivity the server session times out. This can be inconvenient if the user has just been distracted by a phone call in the middle of a complex series of changes.
Some of the users have seen another application which uses JavaScript to "pop up" a warning that the session is about to expire, and they would like such a facility in the application I am working on.
The issues are that there may be anything up to three associated browser windows open, several of them using frames, at any one time, and any or all of them may be updated by clicking links, submitting forms etc. Any JavaScript timeout counter would have to fairly accurately mirror the time-since-last-access used by the JSP server, whichever window the action happened in. And before you ask, no, the overall structure of the interface can't be changed for this feature.
Any suggestions ?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
christoph weingarten
Ranch Hand

Joined: Oct 10, 2002
Posts: 39
if you already know your sessiontimeout this little script could help you:
<html>
<head>
<script type='text/javascript'>
var nowTime = new Date();
var Start = nowTime.getTime();
function myTime() {
var absSec = Math.round(clcTime());
if (absSec>=5) {
alert('TIME IS UP!');
} else {
window.setTimeout('myTime()',1000);
}
}
function clcTime() {
var nowTime2 = new Date();
return((nowTime2.getTime() - Start)/1000);
}
</script>
</head>
<body on_Load="window.setTimeout('myTime()',1000)">
<p>have fun!</p>
</body>
</html>
you only have to change the on_Load into correct syntax. this forum seems to block javascript eventHandler.
regards christoph
ups, i didn't read your whole post.
Any JavaScript timeout counter would have to fairly accurately mirror the time-since-last-access used by the JSP server

so you can forget my suggestion!
[ February 20, 2003: Message edited by: christoph weingarten ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
so Frank, you are saying that the server side web application can not write a little variable onto the page giving the time it was last updated since you can not cange it??
Then you would be able to run a simple script, if it could write a vaiable.....hmmm, okay now lets see here, me digging through the brain....
Okay now, I am just going to ask a few questions, You probably answered them in the above, but my head is full of burger grease right now....
The server application is updated how? Buttons, Links, Page reloads, etc.?
Would you be able to have a code snipplet in each of the frames, talking to the "main" frame?
===
I think I know how to attack it with the above answers.

Eric
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Thanks for the responses, Eric.
you are saying that the server side web application can not write a little variable onto the page giving the time it was last updated since you can not cange it??
Not entirely. The main problem is that the application is composed of at least 40 separate JSPs, and some servlet-generated pages, and I'd prefer not to have to change all of them. There is one page (the "control screen") which is present pretty much all of the time once a user has logged in. It has frames on it (for no particularly good reason), and spits out sub windows for most operations.
The server application is updated how? Buttons, Links, Page reloads, etc.?
Yes, all of the above, and by directly assigning the new location in JavaScript. Even some (horrible) forced form-submits when the user changes a SELECT.
Would you be able to have a code snipplet in each of the frames, talking to the "main" frame?
Theoretically, yes, practically, no, as described above. I doubt I'd find it easy to convince that modifying and manually re-testing every screen in the application would be a good idea, but it may be the only way.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I will play around with some ideas, and see if I can figure out something
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
OKay, I looked into the ocr at psu
ocr is the job recruit place at psu, they use jsp for all of there form stuff. Here is the code they use. I am almost done with my version of this, we will see what happens
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Okay, This is what I have come up with so far........
Basic idea is that this script can be called.
When it is called, it resets the setTimeout.
I have a warning period along with the setout time. This script might be off of millisecs to secs compared to the actual server time do to processing/server speed/ etc.
What you would need to do is set up a dummy thing that would be updated on the server so when the timeout appears, it would just update it. That would keep the server from timing out and the person would not have o submit the unfinished updates they are running.
Right now I am still looking on how to update everything easily. If I were just developing it, I would have put a code that refers to the function
window.opener.StartTimeOut();
parent.MainFrame.StartTimeOut();
in either the action of the form or the click of a link/button
here is a link to my example:
http://www10.brinkster.com/a1ien51/help/Sestime.htm
The page does not actually timeout, amd I set the timeout to be fast!
Now I am still trying to figure out a fast way to merge all of your windows together, As I flip burgers tonight, I will try to think of something!
Eric
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
Regarding the session timeout,
any activity to the server will reset the clock.
The session will timeout only if the user is inactive for 30 min or watever u have defined in ur web.xml file.
So in order to alert the user frst u have to check whether session is active or not using HttpSession, use getSession or isNew.
Then using jave script u can alert the user.
This is wat i did in my app and its working fine.
so if ur session==null and getSession is true
use this js
<script language="javascript">

function restoreSession() {
var rightNow = new Date()
if (confirm(" Your session has been idle for 25 minutes. In five more minutes it will expire. If you wish to continue working press 'OK' now. You will not lose any work. Your session will be active only if you responded within five minutes") )


// there are 1500000 milliseconds in 25 minutes. On this page loading call the restoreSession function in 25 minutes
setTimeout("restoreSession()",1500000);
</script>
so u need only few lines of code
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
This is pretty low tech, but here's a thought:
Have an invisible frame or iframe somewhere in the "control screen." Most pages keep the session alive when loaded, but this hidden page doesn't. All the hidden page has is a short bit of JavaScript that reloads the frame after a little while has passed. The server, not the client, is responsible for knowing how much time is left in the session. When the time gets low and the hidden frame reloads, the JavaScript sent by the server is different -- it displays a warning.
The covers any sort of page reload -- if you want interaction with JavaScript on the page to reset the timer you'll have to somehow notify the server. Probably the best way is the add a feature to the hidden page so that you can set a variable "hiddenFrameName.changed = true" and it reloads with a parameter "?resetSession=true".
 
wood burning stoves
 
subject: Warning a user that something will timeout