test1.jsp
<%@page contentType="text/html" pageEncoding="utf-8"
%><!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>测试页</title>
</head>
<body>
<jsp:include page="test2.jsp"/>
<%=response.getHeader("refresh")%><br><br>
<%=request.getAttribute("info")%>
</body>
</html>
test2.jsp
<%@page contentType="text/html" pageEncoding="utf-8"
%>
<%
response.setHeader("refresh","10;URL=test3.jsp");
request.setAttribute("info","Hello World!!!");
%>
test3.jsp
<%@page contentType="text/html" pageEncoding="utf-8"
%><!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>www.baidu.com</title>
</head>
<body>
<h1>百度一下,你就知道!</h1>
</body>
</html>
浏览器访问test1.jsp,结果如下,为什么是null?
-------------------------------------------------------------------------------
test4.jsp
<%@page contentType="text/html" pageEncoding="utf-8"
%>
<%
response.setHeader("refresh","10;URL=test3.jsp");
%>
<jsp:forward page="test5.jsp"/>
test5.jsp
<%@page contentType="text/html" pageEncoding="utf-8"
%><!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>测试页</title>
</head>
<body>
<span style="font-size:30px">test5</span><br><br>
<%=response.getHeader("refresh")%>
</body>
</html>
浏览器访问test4.jsp,服务器端跳转到test5.jsp,response能正常获取header,且10秒后能跳转到test3.jsp