如何根据 jsp 中的时间重定向到新页面?
how to redirect to new page based on time in jsp?
我想根据时间重定向到新的 jsp 页面。例如,即使有会话过期选项,员工也忘记注销他的帐户。相反,会话过期我可以使用计时器重定向注销页面吗?
可以使用javascriptsetTimeout
方法。
$(document).ready({
setTimeout(function() {
//code for session invalidate and redirect to login page
}, 50000); // calls after 50 seconds
});
开始吧...重定向新页面的方法之一。 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>
我想根据时间重定向到新的 jsp 页面。例如,即使有会话过期选项,员工也忘记注销他的帐户。相反,会话过期我可以使用计时器重定向注销页面吗?
可以使用javascriptsetTimeout
方法。
$(document).ready({
setTimeout(function() {
//code for session invalidate and redirect to login page
}, 50000); // calls after 50 seconds
});
开始吧...重定向新页面的方法之一。 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>