码迷,mamicode.com
首页 > Web开发 > 详细

JSP的几种跳转方式的异同

时间:2017-07-01 13:45:30      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:header   委托   refresh   服务   std   location   服务端   page   end   

 

1 <jsp:foward page="url" />

   服务端跳转,立即跳转,后续语句不会执行;

2 <% response.sendRedirect("url"); %>

   客户端跳转,重定向301方式,返回的response header中会有Location项。跳转前后续代码会继续执行,相当于把跳转动作委托设置于response header中。

3 在Servlet中:RequestDispatcher view = request.getRequestDispatcher("url");

   view.foward(request, response); 

   服务端跳转,跳转前后续代码会继续执行,相当于把跳转动作委托绑定在request对象中。只有在发起response动作时才会解读这里设置的request对象信息。

4 response.setHeader("refresh","3;URL=url");

   客户端跳转,同样类似于response.sendRedirect("url"),只不过可以另外设置附加属性,如跳转时间,而sendRedirect是客户端立即跳转方式。因此同样不会影响后续代码的执行。

 

JSP的几种跳转方式的异同

标签:header   委托   refresh   服务   std   location   服务端   page   end   

原文地址:http://www.cnblogs.com/ioveNature/p/7101973.html

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