10年 Java程序员,硬核人生!勇往直前,永不退缩!

欢迎围观我的git:https://github.com/R1310328554/spring_security_learn 寻找志同道合的有志于研究技术的朋友,关注本人微信公众号: 觉醒的码农,或Q群 165874185

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

这个就是表示 重定向!! 不过,302在不同HTTP协议下的状态信息不同。

302 Moved temporarily (redirect) 你所连接的页面进行了Redirect 

302 Found 类似于301,但新的URL应该被视为临时性的替代,而不是永久性的。注意,在HTTP1.0中对应的状态信息是“Moved Temporatily”,而HttpServletResponse中相应的常量是SC_MOVED_TEMPORARILY,而不是SC_FOUND。出现该状态代码时,浏览器能够自动访问新的URL,因此它是一个很有用的状态代码。为此,Servlet提供了一个专用的方法,即sendRedirect。使用response.sendRedirect(url)比使用response.setStatus(response.SC_MOVED_TEMPORARILY)和response.setHeader("Location",url)更好。这是因为: 

首先,代码更加简洁。 
第二,使用sendRedirect,Servlet会自动构造一个包含新链接的页面(用于那些不能自动重定向的老式浏览器)。 
最后,sendRedirect能够处理相对URL,自动把它们转换成绝对URL。 
注意这个状态代码有时候可以和301替换使用。例如,如果浏览器错误地请求http://host/~user(缺少了后面的斜杠),有的服务器返回301,有的则返回302。 
严格地说,我们只能假定只有当原来的请求是GET时浏览器才会自动重定向。
参考资料: http://zhidao.baidu.com/question/16119833.html?si=4

 

http://segmentfault.com/q/1010000000094621

二者在不同HTTP协议下的状态信息不同。

在HTTP/1.0 302 状态为 Moved Temporarily

The requested resource resides temporarily under a different URL. Since the redirection may be altered on occasion, the client should continue to use the Request-URI for future requests.
在HTTP/1.1 302 状态为 Found

The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field.

 

posted on 2014-11-11 20:50  CanntBelieve  阅读(48182)  评论(1编辑  收藏  举报