Response对象在请求头中设置转发属性
//把响应头中的状态码改为302
response.setStatus(302);
//在请求头中设置location属性为要转发的路径
response.setHeader("location","http://www.sohu.com");
这类请求首先客户端发起初始请求 http://localhost:8080/abc(我们定义的路径) 这个我们配置的请求Servlet
GET /abc HTTP/1.1
Host: localhost:8080
User-Agent: insomnia/6.5.4
Accept: */*
Servlet通过response修改了状态码为302,并在响应头中添加转发路径 location属性,下面的响应信息发送到了客户端浏览
HTTP/1.1 302 < Content-Type: text/html;charset=utf-8 < Content-Language: zh-CN
< location:http://www.sohu.com
< Content-Length: 1072 < Date: Wed, 14 Aug 2019 07:18:10 GMT
浏览器接收到响应消息后,发现响应是302,就在头属性中找出location属性,重新封装下面的Http请求