Struts2 ActionMethod 【DMI】(动态方法调用 Dynamic Method Invoke)
2017-11-18 11:31
423 查看
首先来看 structs.xml 配置文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="user" extends="struts-default" namespace="/user"> <action name="userAdd" class="com.zxh.struts2.user.action.UserAction" method="add"> <result>/user_add_success.jsp</result> </action> <action name="user" class="com.zxh.struts2.user.action.UserAction"> <result>/user_add_success.jsp</result> </action> </package> </struts>
然后来看UserAction中的代码
import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { public String add() { return SUCCESS; } }
Action执行的时候并不是一定要执行execute方法:
1.可以在配置文件struts.xml中配置Action的时候用method=”“来制定执行那个方法,但是会产生太多的action,所以不太推荐此种方式。
2.可以在url地址中动态指定(动态方法调用DMI),如本例中的就可以这样输入url
http://localhost:8080/Struts2_0500_ActionMethod/user/user!add
此时就会调用
<action name="user" class="com.zxh.struts2.user.action.UserAction"> <result>/user_add_success.jsp</result> </action>
中指明的UserAction的add方法
相关文章推荐
- struts2 2.5动态方法调用(DMI) dynamic method invoke 出现不被允许的方法时 Method add for action dynamic is not allowed! - [unknown location]
- Struts2 ActionMethod 【DMI】(动态方法调用)
- Struts2_05_ActionMethod动态方法调用_DMI
- 有关Struts2_ActionMethod_DMI_动态方法调用的学习
- Struts2_5_ ActionMethod_DMI_动态方法调用
- struts2配置及ActionMethod_DMI_动态方法调用
- Struts2 ActionMethod DMI(动态方法调用)
- DMI(Dynamic Method Invocation) 动态方法调用
- struts2 ActionMethod DMI 动态方法调用
- Struts2中DMI(动态方法调用)
- Struts2动态方法调用(DMI)
- Struts2中使用DMI(动态方法调用)
- struts2动态方法调用 ActionName!methodName.action
- Struts2 DMI 动态方法调用
- Struts2 1.动态方法调用(1.指定method2.感叹号方式3.通配符方式)2.隐藏后缀名(三种方式)
- struts.enable.DynamicMethodInvocation = true 动态方法调用
- Struts2中DMI(动态方法调用)的一些问题
- Struts2动态方法调用(DMI)小问题
- 【Struts2复习知识点五】-ActionMethod 动态指定调用方法
- ActionMethod 动态方法调用(DMI)