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

查看:32
本文介绍了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 时使用相同的请求属性和相同的请求参数.并且浏览器不会知道 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) 要求客户端执行临时重定向(最初的描述短语是Moved暂时"),但流行的浏览器实现了 302303 查看其他的功能.因此,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天全站免登陆