respond页面刷新效果:
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Date date = new Date();
//String dateFormatStr="yyyy-M-dd\n\tH:mm:ss";
String dateFormatStr="yyyy:MM:dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(dateFormatStr);
out.print("<h3 align=center >现在时间为:"+sdf.format(date)+"</h3>");
response.setHeader("Refresh", "1");//每隔一秒刷新一次
%>
</body>
</html>
效果:
说明:
上面的时间是每一秒都在不断的变化,这就是刷新的作用
response.setHeader(“Refresh”, “1”);//每隔一秒刷新一次
respond页面跳转:
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>
3秒后跳转到主页面,如果没有跳转<a href="../index.jsp">请点击这里</a>
</h3>
<%
//response.setHeader("refresh", "3;URL=http://localhost:8080/First/index.jsp");//页面跳转
response.sendRedirect("http://localhost:8080/First/index.jsp");//页面跳转
System.out.println("**************跳转后的代码****************");//输出语句可以正常输出
%>
</body>
</html>
说明:
response.setHeader(“refresh”, “3;URL=http://localhost:8080/First/index.jsp”);//页面跳转
这是三秒后进行的跳转,跳转到后面链接(省略http://localhost:8080也是可以的)
说明:
response.sendRedirect(“http://localhost:8080/First/index.jsp”);//页面跳转
这是页面立即跳转((省略http://localhost:8080也是可以的))
说明:
下面图中可以看出页面跳转后面的输出语句可以正常的输出,这里注意区分与forward跳转的区别