Struts2的Action多方法调用

Action多方法调用
        方式一:
            在struts.xml中的action标签中添加method值如:
        
            <!-- 没有method属性值则这是MyTestAction默认的调用方法即execute方法将被调用 -->
            <action name="myTest" class="com.mengya.action.MyTestAction">
                <result name="success">/index.jsp</result>
            </action>
            
            <!-- method属性值为text1则这是MyTestAction调用方法即text1方法将被调用 -->
            <action name="text1" class="com.mengya.action.MyTestAction" method="text1">
                <result name="success">/index.jsp</result>
            </action>        
        
        方式二:
            在struts.xml中的action标签不改
            <action name="myTest" class="com.mengya.action.MyTestAction">
                <result name="success">/index.jsp</result>
            </action>
            页面修改:
            <a href="myTest.action">Action默认的方法</a><br>
              <a href="myTest!text1.action">Action的text1方法</a><br>
              <a href="myTest!text2.action">Action的text2方法</a>
              
        方式三:通配符
            struts.xml的配置:
            <action name="myTest_*" class="com.mengya.action.MyTestAction" method={1}>

                <result name="success">/index.jsp</result>
            </action>                       
            页面:
            <a href="myTest.action">Action默认的方法</a><br>
              <a href="myTest_text1.action">Action的text1方法</a><br>

              <a href="myTest_text2.action">Action的text2方法</a>

猜你喜欢

转载自ears.iteye.com/blog/1535180