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

          posted on 2011-02-18 16:27 小羅 閱讀(2512) 評論(1)  編輯  收藏

          評論

          # re: struts控制器中使用new ActionForward和mapping.findForward的區別 2013-07-23 16:20 吃飯

          回家哦那里呢  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2011年2月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272812345
          6789101112

          導航

          統計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          Web Framework

          常上的技術網站

          查找資料的java網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 永定县| 北票市| 桂东县| 桂平市| 铁力市| 奉化市| 凤城市| 同仁县| 郧西县| 吉林市| 富源县| 漳州市| 顺义区| 奉新县| 育儿| 石狮市| 乌拉特后旗| 普洱| 兴山县| 鄂托克旗| 郓城县| 聂荣县| 定襄县| 全椒县| 太和县| 东阿县| 商城县| 婺源县| 南乐县| 临颍县| 万盛区| 佛山市| 东丽区| 桃园市| 麻栗坡县| 黄石市| 七台河市| 东乡族自治县| 根河市| 甘洛县| 铁力市|