码迷,mamicode.com
首页 > 其他好文 > 详细

302 Moved Temporarily

时间:2014-11-11 22:19:30      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   os   使用   

 

这个就是表示 重定向!! 不过,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.

 

302 Moved Temporarily

标签:des   style   blog   http   io   color   ar   os   使用   

原文地址:http://www.cnblogs.com/FlyAway2013/p/4090493.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!