码迷,mamicode.com
首页 > 其他好文 > 详细

转发与重定向的区别

时间:2019-12-10 00:30:05      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:isp   jsp   jsp页面   传输   attribute   行数据   res   nbsp   定向   

转发时浏览器中的url地址栏不会发生改变,重定向时地址栏会发生改变

转发时浏览器只请求一次服务器,重定向时浏览器请求两次服务器

转发的代码:

request.getRequestDispatcher("要转发的jsp页面").forward(request,response);

重定向的代码:

response.sendRedirect("jsp的路径");

注意:重定向无法通过request和response传输数据,但可用以下方法进行数据的传输

this.getServletContext().setAttribute("属性名",属性值);
 request.getSession().setAttribute("属性名",属性值);

 

转发与重定向的区别

标签:isp   jsp   jsp页面   传输   attribute   行数据   res   nbsp   定向   

原文地址:https://www.cnblogs.com/shouyaya/p/12014123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!