动态调用action方法,是指用 action!method 格式的请求来请求后台的逻辑处理
前提条件:在struts.xml或者struts.properties中配置
struts.enable.DynamicMethodInvocation常量为true ,否则动态调用不可用
查看源码: 在org.apache.struts2.dispatcher.mapper.DefaultActionMapper中
protected ActionMapping parseActionName(ActionMapping mapping)
{
if(mapping.getName() == null)
return null;
//该参数即struts.enable.DynamicMethodInvocation常量的值,
//因此设为true,才可以用动态调用请求action
if(allowDynamicMethodCalls)
{
String name = mapping.getName();
int exclamation = name.lastIndexOf("!");
if(exclamation != -1)
{
mapping.setName(name.substring(0, exclamation));
mapping.setMethod(name.substring(exclamation + 1));
}
}
return mapping;
}
注意:通配符格式的action请求与参数struts.enable.DynamicMethodInvocation的值无关
原文地址:http://wangyaojie.blog.51cto.com/8877058/1568272