重定向 不传值
跳转 可以传值
<================重定向==================>
<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&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时候效果一样。