倒计时页面跳转、jsp 中如何使页面停留几秒后再转向其他页面

时间:2021-06-09 22:07:57
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>请勿重复提交您的信息!谢谢!</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->


<script type="text/javascript">
var time = 4;


function returnUrlByTime() {


window.setTimeout('returnUrlByTime()', 1000);


time = time - 1;


document.getElementById("layer").innerHTML = time;
}
</script>


</head>


<body  onload="returnUrlByTime()">

<h3>请勿重复提交您的信息!谢谢!</h3>
<b><span id="layer">3</span>秒后,转入输入界面。</b>

<%
//转向语句
response.setHeader("Refresh", "3;URL=for_input.jsp");
%>


</body>

</html>


==========第二例子===========


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
<head>  
<title>请勿重复提交您的信息!谢谢!</title>  
</head>
  
<script type="text/javascript">
 function countDown(secs) {
  document.getElementById("jump").innerHTML = secs;
  if (--secs > 0){
   setTimeout("countDown(" + secs + " )", 1000);
   }else{
  <%-- 填写跳转地址--%>
   location.href="index.jsp";
   }
 }
 </script>
 
<body style="overflow: auto;" onload="javascript:countDown(5);">


<div align="center">......页面将在<span id="jump"></span>秒后自动跳转......
</div>
</body>  
</html>