struts2 动态方法调用

如果 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"/>

猜你喜欢

转载自free0007.iteye.com/blog/1757239