2015-02-09 143 views
1

我想根據時間重定向到新的jsp頁面。例如,即使有會話過期選項,員工也會忘記註銷其帳戶。相反,會話過期可以使用計時器重定向登出頁面嗎?如何在jsp中基於時間重定向到新頁面?

+0

爲什麼你希望單獨完成,儘管你有一個選項。 _pls使用,而不是發明_ – 2015-02-09 06:05:42

+0

爲學習目的...這將有助於其他人。你有什麼想法,請讓我知道。 – venkat 2015-02-09 06:12:56

回答

0

您可以使用javascript setTimeout方法。

$(document).ready({ 
setTimeout(function() { 
    //code for session invalidate and redirect to login page 
    }, 50000); // calls after 50 seconds 

}); 
+0

謝謝你的朋友,它工作正常 – venkat 2015-02-11 07:51:16

+0

我很高興我的回答對你有幫助。 – Wahab 2015-02-12 06:59:32

0

這裏我們去...重定向新頁面的一種方法。 5秒後,該頁面將被重定向到註銷頁面。

<script> 
var timeout = 5; //set time here 5sec 
function timer(){ 
    if(--timeout > 0){ 
     document.forma.clock.value = timeout; 
     window.setTimeout("timer()", 1000); 
    } 
    else{ 
    document.forma.clock.value = "Time over"; 
    ///disable submit-button etc 
    } 
    if(document.forma.clock.value=="Time over"){ 
    top.document.location.replace('logout.jsp'); //redirect page url 
    } 
}  
</script> 
<body> 
    <form name="forma"> 
     <% String clock = null; %>  
     You will be logged out after:<input type="text" size='1' name="clock" value="<%=clock%>" style="border:1px solid white">seconds 
    <script> 
     timer(); //calljs timer() 
    </script> 
    </form> 
</body> 
</html>