struts控制器中使用new ActionForward和mapping.findForward的區(qū)別

          struts控制器中使用new ActionForward和mapping.findForward的區(qū)別

          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請求,所以可以攜帶參數(shù)setAttribute過去。
                                      無論 <forward
                                       name="succ"
                                       path="/success.jsp"
                                      redirect="true" />//無論此處的redirect是true還是false。

          當使用 return mapping.findForward("fail");的時候如果 redirect="true",相當于還是另外一個request請求,所以不能攜帶參數(shù)setAttribute過去。
                           要想還是使用同一個request,獲取到參數(shù),則把
                                              <forward
                                       name="succ"
                                       path="/success.jsp"
                                      redirect="false" />//此處的redirect改為false。另外,此處不設置的話默認redirect="false"。

          無論在任何情況下使用
          request.getSession().setAttribute("a", "sssss");都可以傳遞參數(shù)。
          在頁面處獲取 <%=request.getSession().getAttribute

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

          評論

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

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


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


          網(wǎng)站導航:
           
          <2011年2月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272812345
          6789101112

          導航

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          Web Framework

          常上的技術網(wǎng)站

          查找資料的java網(wǎng)站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 阳谷县| 新和县| 德化县| 清涧县| 丽江市| 桐乡市| 黄平县| 漯河市| 板桥市| 惠安县| 鲁甸县| 云林县| 厦门市| 陆河县| 贡山| 京山县| 郓城县| 分宜县| 文登市| 景德镇市| 喜德县| 晋宁县| 翁源县| 十堰市| 定远县| 莲花县| 肇州县| 尼木县| 龙州县| 五常市| 开江县| 夏津县| 宜兰县| 惠州市| 丰台区| 高邮市| 基隆市| 保定市| 蕲春县| 镇雄县| 新疆|