Java世界

          學習筆記

          常用鏈接

          統計

          積分與排名

          天籟村

          新華網

          雅虎

          最新評論

          Struts2學習筆記——3

          Action執行的時候并不一定要執行execute方法。
          可以在配置文件中配置Action的時候用method=來指定執行哪個方法也可以在url地址中動態指定(動態方法調用DMI)(推薦),前者會產生太多的action,所以不推薦使用。

          struts2.xml中的配置:
          <action name="hello" class="test.struts2.TestAction">
                <result>/Hello.jsp</result>
                <result name="add">/add.jsp</result>     name表示方法返回的結果的字符串相對應。
                <result name="update">/update.jsp</result>
          </action>

          jsp頁面中的代碼:
          <a href="test/hello">hello</a><br>
          <a href="test/hello!add">hello!add</a><br>   !表示代碼的動態調用,我要使用該action中的哪個方法。
          <a href="test/hello!a">hello!update</a>

          action中的代碼:
          public class TestAction extends ActionSupport {
           
           public String execute() {
            return "success";
           }
           
           public String add() {    //add() 對應DMI的!號后的字符就是方法名
            return "add";              //返回的add對應struts2.xml中的result的name值,找到相對應的結果。
           }
           
           public String update() {
            return "update";
           }

          }

          posted on 2010-07-01 10:24 Rabbit 閱讀(163) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 防城港市| 碌曲县| 兴海县| 平潭县| 常宁市| 靖西县| 娄烦县| 湘潭市| 榕江县| 洱源县| 平顺县| 宝应县| 禹州市| 内黄县| 鄱阳县| 阿城市| 连云港市| 驻马店市| 沁阳市| 肥西县| 凉城县| 页游| SHOW| 潍坊市| 西青区| 台南县| 潢川县| 乌鲁木齐县| 合作市| 宁乡县| 鄂托克旗| 隆林| 阜阳市| 奉节县| 扬中市| 屏南县| 齐河县| 五华县| 梧州市| 惠来县| 德钦县|