想飛就別怕摔

          大爺?shù)牟M罵人

          struts2學習筆記(五)--result返回值的其他用法

          result可以動態(tài)的返回。方便了struts2的使用,不過這種方法很少使用。
          第一種result返回值方法
          struts.xml中的配置如下:
          <struts>
              
          <constant name="struts.devMode" value="true" />
              
          <package name="user" namespace="/user" extends="struts-default">
                  
                  
          <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
                      
          <result>${r}</result>
                  
          </action>        
              
          </package>
                  
          </struts>
          action的寫法:
          public class UserAction extends ActionSupport {
              
          private int type;
              
              
          private String r;

              
          public String getR() {
                  
          return r;
              }

              
          public void setR(String r) {
                  
          this.r = r;
              }

              
          public int getType() {
                  
          return type;
              }

              
          public void setType(int type) {
                  
          this.type = type;
              }

              @Override
              
          public String execute() throws Exception {
                  
          if(type == 1) r="/user_success.jsp";
                  
          else if (type == 2) r="/user_error.jsp";
                  
          return "success";
              }

          }

          第二種result返回值方法
          struts.xml中的配置如下,這種方法可以把type值傳遞到頁面中去。在頁面中可以渠道type的值,<s:property value="#parameters.t">
          <struts>
              
          <constant name="struts.devMode" value="true" />
              
          <package name="user" namespace="/user" extends="struts-default">
                  
                  
          <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
                      
          <result type="redirect">/user_success.jsp?t=${type}</result>
                  
          </action>        
              
          </package>
                  
          </struts>
          action的寫法:

          public class UserAction extends ActionSupport {
              
          private int type;
              
              
          public int getType() {
                  
          return type;
              }

              
          public void setType(int type) {
                  
          this.type = type;
              }

              @Override
              
          public String execute() throws Exception {
                  
          return "success";
              }

          }

          posted on 2011-12-11 13:23 生命的綻放 閱讀(2180) 評論(1)  編輯  收藏 所屬分類: Struts2.0

          評論

          # re: struts2學習筆記(五)--result返回值的其他用法[未登錄] 2013-12-29 15:59 A

          A  回復  更多評論   

          <2013年12月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          導航

          統(tǒng)計

          常用鏈接

          留言簿(5)

          隨筆分類(94)

          隨筆檔案(93)

          文章分類(5)

          文章檔案(5)

          相冊

          JAVA之橋

          SQL之音

          兄弟之窗

          常用工具下載

          積分與排名

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 崇文区| 汶川县| 乃东县| 顺昌县| 江西省| 肇东市| 宜兰县| 屯昌县| 孝义市| 清新县| 桑日县| 军事| 霍林郭勒市| 阜南县| 中山市| 梧州市| 东安县| 容城县| 吐鲁番市| 通州区| 中西区| 方正县| 含山县| 平遥县| 玉树县| 邻水| 龙山县| 长寿区| 兰西县| 民丰县| 金乡县| 孙吴县| 察隅县| 金湖县| 涪陵区| 聂拉木县| 莲花县| 防城港市| 石家庄市| 凤山县| 融水|