response对象

response对象主要用于对客户端的请求进行回应,将web服务器处理后的结果发回给客户端,封装了jsp产生的响应,并发送到客户端响应客户端的请求,请求的数据可以是各种数据类型,甚至是文件。

常用的方法:void addcookie(cookie c) 添加一个cookie对象,用来保存客户端用户信息。

比如一些登录操作是否记住用户名等等。void setheader(string name,string value) 常用的有刷新操作和定时跳转页面。

response.setheader(“refresh”,“1”),response.setheader(“refresh”,“2:url=xxx”)。

void sendredirect(string url)设置页面重定向。

举例1:时间动态显示

<%@ page language="java" contenttype="text/html; charset=utf-8"
	pageencoding="utf-8"%>
<%@ page import="java.util.*"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>日期的更新</title>
</head>
<body>
	<%
		//void setheader(string name,string value)
		//功能:常用的刷新refresh,例如:response.setheader("refresh","1")
		//几秒后跳转:response.setheader("refresh","2:url=xxx")
		date now = new date();
		out.print(now.tolocalestring());
		response.setheader("refresh", "1");//一秒刷新一次
	%>

</body>
</html>

页面的重定向:

<%@ page language="java" contenttype="text/html; charset=utf-8"
	pageencoding="utf-8"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>页面重定向</title>
</head>
<body>
	<%
		/*
		*在浏览器进行重定向。跳转时机,当页面代码执行完毕,
		*把响应发送给客户端之后,客户端再根据
		*重新指向的url地址。浏览器地址栏中的地址是改变的
		*/
		response.sendredirect("response3.jsp");
	%>

</body>
</html>

跳转的页面

<%@ page language="java" contenttype="text/html; charset=utf-8"
    pageencoding="utf-8"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>重定向后的内容</title>
</head>
<body>
<h1>重定向后的页面</h1>
</body>
</html>

到此这篇关于jsp response对象页面重定向、时间的动态显示的文章就介绍到这了,更多相关jsp response页面重定向内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!