RequestDispatcher.forward()和HttpServletResponse.sendRedirect()有什么区别?

RequestDispatcher.forward()和HttpServletResponse.sendRedirect()有什么区别?,第1张

RequestDispatcher.forward()和HttpServletResponse.sendRedirect()有什么区别

重定向是一种发送回客户端的响应,而转发委托完全在服务器端进行,转发 *** 作的结果将返回给客户端,就好像它仅来自原始URL。

另一个区别是前向委派只能用于应用程序内资源,而重定向命令可以将客户端浏览器重定向到当前域之外。

例子:
// Sends a temporary redirect to the HTTP client. only absolute URLs are allowed.ServletResponse.sendRedirect(String location);// Delegates one HttpRequest to another dynamic or static resourceHttpRequest.getRequestDispatcher("example.jsp").forward(request, response);// Includes/enriches current response with another dynamic or static resourceHttpRequest.getRequestDispatcher("example.html").include(request, response);

在这里可以找到另一个很好的解释:
sendRedirect()和forward()之间的区别



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5561525.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存