(二十):response 对象 (JSP学习第六天)
response 对象
主要作用是对客户端的请求进行回应,将WEB服务器的处理结果发回客户端,
response对象属于javax.servlet.http.HttpServletResponse接口的实例
HttpServletResponse接口定义如下:
public interface HttpServletResponse extends ServletResponse
设置头信息
设置定时刷新头信息response_demo01.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%>
<html>
<title>测试</title>
<body>
<%! int count=0;
%>
<%
response.setHeader("refresh","2");
%>
<h3>你已经访问了<%=count++%>次</h3>
</body>
</html>
3秒钟跳转到其他页面 response_demo02.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%>
<html>
<head>
<title>测试</title>
</head>
<body>
<h3>3秒后跳转到hello.html页面,如果没有请按<a href="hello.html">这里</a></h3>
<%
response.setHeader("refresh","3;url=hello.html");
%>
</body>
</html>
跳转之后浏览器地址已经发生改变,这种定时跳转属于客户端跳转,
还可以使用html页面进行页面的跳转response_demo03.html
<html> <head> <title>测试</title> </head> <META HTTP-EQUIV="refresh" CONTENT="3;URL="hello.html"> <body> <h3>3秒后跳转到hello.html页面,如果没有请按<a href="hello.html">这里</a></h3> </body> </html>
只有当一个页面没有jsp代码的是才用html形式的设置跳转的头信息(说得有点简单,初学者就是这样,暂且就这么说吧,以后有时间继续补充)
浙公网安备 33010602011771号