栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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()之间的区别



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570280.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号