在使用DMI(动态方法调用)的时候要注意struts.xml配置时要把
代码语言:javascript复制<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
不然会出现错误
完整示例代码
struts.xml
代码语言:javascript复制 <constant name="struts.devMode" value="true" />
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<package name="default" namespace="/path" extends="struts-default">
<action name="path" class="com.pengli.structs2.actionstudy.IndexAction3">
<result name ="a">
/MyPath.jsp
</result>
</action>
</package>
<package name="default2" namespace="/" extends="struts-default">
<action name="path2" class="com.pengli.structs2.actionstudy.IndexAction3">
<result name ="a">
/MyPath.jsp
</result>
<result name ="add">
/hello.jsp
</result>
<result name ="edit">
/index.jsp
</result>
</action>
</package>
IndexAction3
代码语言:javascript复制package com.pengli.structs2.actionstudy;
import com.opensymphony.xwork2.ActionSupport;
public class IndexAction3 extends ActionSupport{
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return "a";
}
public String add()
{
return "add";
}
public String edit()
{
return "edit";
}
}
web.xml
代码语言:javascript复制 <filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>