一、基本信息
1、作用:对客户的请求做出响应,向客户端发送数据。
(一)重定向
1、响应客户时,将客户重定向到另一个页面。
2、使用response对象的sendRedirect(url)方法。
3、特点
- 重定向支持定向到不同的主机(可以重定向到其他服务器或者其他web应用中的url。转发不可以,转发必须是同一个应用中的)
- 浏览器显示跳转后的地址(重定向显示的是重定向之后的页面,转发的话是之前的页面)
- 重定向后,request中 的属性全部失效
4、实例
例1:
index.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Ê×Ò³</title>
</head>
<body>
<%//response.sendRedirect("login.jsp"); %>
<%response.sendRedirect("http://www.sina.com.cn"); %>