Java世界

          學習筆記

          導航

          <2010年7月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          留言簿(11)

          收藏夾

          隨筆檔案

          文章檔案

          閱讀排行榜

          評論排行榜

          常用鏈接

          統(tǒng)計

          積分與排名

          天籟村

          新華網(wǎng)

          雅虎

          最新評論

          Struts2學習筆記——3

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

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

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

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

          }

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


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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 宁河县| 岳池县| 雷山县| 金阳县| 即墨市| 庆元县| 景泰县| 盐城市| 罗江县| 大方县| 浙江省| 蓬安县| 玉门市| 霍邱县| 吕梁市| 阿拉善右旗| 东乌珠穆沁旗| 襄垣县| 日喀则市| 汾阳市| 息烽县| 新化县| 辽源市| 新和县| 永川市| 永春县| 新源县| 高安市| 巴马| 莒南县| 霍林郭勒市| 陵川县| 惠安县| 修文县| 砚山县| 肃南| 砀山县| 公主岭市| 新安县| 禄丰县| 昌宁县|