【学习笔记11】动态方法调用和使用通配符定义action
生活随笔
收集整理的這篇文章主要介紹了
【学习笔记11】动态方法调用和使用通配符定义action
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
動態方法調用:如果Action中存在多個方法時,我們可以使用 !+方法名調用指定方法。如下:
public class HelloWorldAction{private String message;...public String execute() throws Exception{this.message = "我的第一個struts2應用";return "success";}public String other() throws Exception{this.message = "第二個方法";return "success";} } 假設訪問上面action的URL路徑為: /struts/test/helloworld.action
要訪問action的other() 方法,我們可以這樣調用:/struts/test/helloworld!other.action
如果不想使用動態方法調用,我們可以通過常量struts.enable.DynamicMethodInvocation關閉動態方法調用。
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
使用通配符定義action:<package name="itcast" namespace="/test" extends="struts-default"><action name="helloworld_*" class="cn.itcast.action.HelloWorldAction" method="{1}"><result name="success">/WEB-INF/page/hello.jsp</result></action> </package>
要訪問other()方法,可以通過這樣的URL訪問:/test/helloworld_other.action
(本學習筆記是根據傳智播客的視頻教程整理而來)
轉載于:https://my.oschina.net/zc741520/blog/122705
總結
以上是生活随笔為你收集整理的【学习笔记11】动态方法调用和使用通配符定义action的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: onMeasure onLayout用
- 下一篇: mysql数据库解除外键