java web延时跳转以及延时跳转并显示时间
1.jsp延时跳转
通过session传递数据,response无法传输request中的数据。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>延时跳转</title>
</head>
<body>
<h1>
<%
out.print("准备跳转");
String name="黎明";
session.setAttribute("name", name);
response.setHeader("Refresh","5;URL=a01b.jsp");
%>
</h1>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>延时跳转</title>
</head>
<body>
<p>延时跳转</p>
<hr>
<%
String Name=(String)session.getAttribute("name");
out.println(Name);
%>
</body>
</html>
2.jsp延时跳转并显示时间
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="javascript">
var times = 6;
clock();
function clock() {
window.setTimeout('clock()', 1000);
times = times - 1;
time.innerHTML = times;
}
</script>
<head>
<meta http-equiv="Refresh" content="5;url=a02b.jsp ">
</head>
<body>
<table>
<tr>
<td>页面将于</td>
<td><div id="time">5</div></td>
<td>秒后跳转...</td>
</tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
已跳转到新页面!!!
</body>
</html>