重定向和跳转

重定向  不传值
跳转  可以传值

 <================重定向==================>
 <forward name="list"   redirect="true"  path="/jsp/sunny/sales/inquiry/inquiry.jsp">
 </forward>
 <forward name="ok" redirect="true"  path="/jsp/Office/WorkFlow/result.jsp">
 </forward>
 
 <================跳转==================>
 <forward name="saveOrUpdate"  path="/jsp/sunny/sales/inquiry/copy.jsp">
 </forward>

方式1   跳转
return mapping.findForward("saveOrUpdate");

方式2   重定向(不能传值)
return mapping.findForward("saveOrUpdate");

方式3   重定向(可以传值)
ActionForward actionForward = new ActionForward(mapping.findForward("list").getPath()+"?opportunityId="+opportunityId+"");
actionForward.setRedirect(true);
return actionForward;

方式4   跳转到action   方法
return finishedProjectQuery(mapping,form,request,response);

方式5   直接调整到jsp页面(不用在配置文件中配置页面路径)
return new ActionForward("/jsp/homepage/personal/index/perindex.jsp");


response.sendRedirect("../jsp/message_center/NoticeHand.jsp?notice_status="+noticeRemind.get("status").toString());

配置文件跳转
<forward name="list" redirect="true" path="/ofCardDataInit.do?fromUrl=cmnCardList&amp;method=query"></forward>


---------------------------------------------------------------------------------------------------------------

struts控制器中使用new ActionForward和mapping.findForward的区别 

struts控制器中使用new ActionForward和mapping.findForward的区别

request.setAttribute("list", new Integer(0));
                       return  new ActionForward("/success.jsp");

request.setAttribute("list", new Integer(0));
   return mapping.findForward("fail");

当使用 return  new ActionForward("/success.jsp");的时候相当于还是同一个request请求,所以可以携带参数setAttribute过去。
                            无论 <forward
                             name="succ"
                             path="/success.jsp"
                            redirect="true" />//无论此处的redirect是true还是false。

当使用  return mapping.findForward("fail");的时候如果 redirect="true",相当于还是另外一个request请求,所以不能携带参数setAttribute过去。
                 要想还是使用同一个request,获取到参数,则把
                                    <forward
                             name="succ"
                             path="/success.jsp"
                            redirect="false" />//此处的redirect改为false。另外,此处不设置的话默认redirect="false"。

无论在任何情况下使用
request.getSession().setAttribute("a", "sssss");都可以传递参数。
在页面处获取 <%=request.getSession().getAttribute("a")%>

 

另外,使用 new ActionForward时候地址栏不会出现jsp页面,当使用session携带参数的时候会显示sessionid在地址栏,和使用mapping.findForward当redirect改为false时候效果一样。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值