admin管理员组

文章数量:1277903

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 e. I need this changes in javascript and jsp. Can any one have idea about this?

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 e. I need this changes in javascript and jsp. Can any one have idea about this?

Share Improve this question edited Nov 24, 2011 at 12:47 robert 8,7179 gold badges46 silver badges70 bronze badges asked Nov 24, 2011 at 12:34 NagarajanNagarajan 4323 gold badges12 silver badges28 bronze badges 2
  • Use setTimeout() function in JS – Aleks G Commented Nov 24, 2011 at 12:38
  • Alerk am using frameset. On Page load i gave the frame set. On each time loading the frame it is resetting. – Nagarajan Commented Nov 24, 2011 at 12:41
Add a ment  | 

2 Answers 2

Reset to default 6

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.

I'm not sure if you're looking for a plete 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.

本文标签: javascriptSession Timeout creation for applicationStack Overflow