请解释一下 jsp:forward
之间的区别和redirect
。
每种情况发生了什么?
最佳答案
redirect 将响应状态设置为 302 [1],并在
Location
header 中设置新 URL,并将响应发送到浏览器。然后浏览器根据http规范,向新的url再次发出请求转发完全发生在服务器上。 servlet 容器只是将相同的请求转发到目标 url,而浏览器不知道这一点。因此,在处理新 url 时,您可以使用相同的请求属性和相同的请求参数。并且浏览器不会知道 url 已更改(因为它完全发生在服务器上)
[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 - JSP转发和重定向的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6068891/