Reputation: 432
I have a requirement for session timeout. This is my requirement. Once logged in to my application, a time count sholud start. If it reaches 10 mins, it should gives a alert which prompting as
do you want to continue?
If customer press "Yes" the session should continue and time resetted as 0. If press "No", the session should close and error page need to come. I need this changes in javascript and jsp. Can any one have idea about this?
Upvotes: 3
Views: 14074
Reputation: 57306
In your frameset file, you can have this:
<script type="text/javascript">
window.setTimeout('checkIfContinue()', 10*60*1000); //10 minutes
function checkIfContinue()
{
if(confirm("Do you want to continue?"))
{
window.setTimeout('checkIfContinue()', 10*60*1000); //start the timer again
}
else
{
window.location = 'timeout.html';
}
}
</script>
Of course, if you need a fancy dialog box, then you'll need to code that instead of using javascript function confirm
.
Upvotes: 6
Reputation: 3830
I'm not sure if you're looking for a complete code example. But briefly, I would say that you should use ajax on the client side to ping the server once a minute or so, to see if the timeout has expired. But then, if it has, there's a challenge. The server tells the client, "the session has expired," but then what? If the user doesn't respond with "yes," you want the session to timeout? If so, then how long does the server wait to hear back from the client before timing out? What if the user doesn't click "yes" for 30 seconds? So it can get sticky, and you would have to decide on the rules.
If no action is taken unless the user clicks "no" then this isn't a problem.
However I should also say that I don't think it's a good idea to ask visitors if they want to continue. It makes visitors feel like they are being pestered to leave.
Upvotes: 2