jsp - JSP转发和重定向的区别

标签 jsp redirect servlets forward

请解释一下 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/

相关文章:

java - 关于读取 jar 文件的错误

java - 将请求从 servlet 重定向到 jsp 时出现 404 错误

java - jsp:包含文件未找到异常

java - JSP request.getParameter(string) 返回 null

AngularJS 路由提供程序不起作用

javascript - 我需要重定向方面的帮助

python - 使用 PyFacebook 和 Google App Engine 循环重定向

java - JSP Servlet session invalidate() 不会使 session 为空

java - 有没有办法使用 Tomcat API 从应用程序内部重新启动 webapp?

java - 从 Java Servlet 运行 R 代码