重定向 不傳值
跳轉 可以傳值
<================重定向==================>
<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時候效果一樣。