JSP转发和重定向之间的区别 [英] Difference between JSP forward and redirect

查看:75
本文介绍了JSP转发和重定向之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请说明jsp:forwardredirect之间的区别.
在每种情况下会发生什么?

Please explain the difference between jsp:forward and redirect.
What is happening in each case?

推荐答案

  • redirect将响应状态设置为302 [1],并在Location标头中设置新的url,然后将响应发送到浏览器.然后,浏览器根据http规范,再次请求新的URL

    • redirect sets the response status to 302 [1], and the new url in a Location header, and sends the response to the browser. Then the browser, according to the http specification, makes another request to the new url

      转发完全在服务器上进行. Servlet容器只是将相同的请求转发到目标url,而浏览器对此一无所知.因此,在处理新的URL时,您可以使用相同的请求属性和相同的请求参数.而且浏览器不会知道网址已更改(因为它完全在服务器上发生了)

      forward happens entirely on the server. The servlet container just forwards the same request to the target url, without the browser knowing about that. Hence you can use the same request attributes and the same request parameters when handling the new url. And the browser won't know the url has changed (because it has happened entirely on the server)

      [1]:这是违反标准的行业惯例的示例. HTTP/1.0规范(RFC 1945)要求客户端执行 临时重定向(最初的描述词组是已移动 暂时"),但流行的浏览器使用302实现了 303的功能请参阅其他".因此,HTTP/1.1添加了状态 代码303和307来区分这两种行为.然而, 一些Web应用程序和框架使用302状态代码,就像它使用 是303.来源

      [1]: This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303. Source

      这篇关于JSP转发和重定向之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆