JSP、HTML定时跳转

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/chu_jian86a/article/details/79532406

JSP的response对象利用setHeader方法设置head信息,实现页面定时跳转的功能。

void setHeader(String name,String value) 设置制定HTTP头的值。设定指定名字的HTTP文件头的值,若该值存在,它将会被新值覆盖。

response.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>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定时跳转</title> 
</head>
<body>
	<h3>3秒后跳转到meta_refresh.html页面,若没有跳转请点击<a href="meta_refresh.html">这里</a></h3>
	<% response.setHeader("refresh", "3;URL=meta_refresh.html"); %>
</body>
</html>

HTML的meta标记本身也可以设置头信息:

meta_refresh.html:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="4;url=response.jsp" charset="UTF-8">
<title>HTML 定时跳转</title>
</head>
<body>
	<h3><font color="red">4秒后跳转到response.jsp页面,若没有跳转请点击</font><a href="response.jsp">这里</a></h3>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/chu_jian86a/article/details/79532406
今日推荐