Struts2 ActionMethod DMI(动态方法调用)
2011-07-30 22:13
351 查看
Action执行的时候并不是一定要执行execute方法
可以在配饰魏积安中配置Action的时候用method=来制定执行那个方法,
也可以在url地址中动态指定(动态方法调用MDI)
要说明的是:
前者会产生太多的action
如:<action name="user" class="com.b510.hongten.UserAction" method="add">
<result>/user.jsp</result>
</action>
<action neme="user" class="com.b510.hongten.UserAction" method="sub">
<result>/user.jsp</result>
</action>
...
</action>
后者只用一个action就可以做到这些,只是在url中输入方法名即可
<action name="user" class="com.b510.hongten.UserAction">
<result>/user.jsp</result>
</action>
调用的时候我们在url中这样写:
http://localhost:1000/struts2_0500_actionMethod/user/user!add
http://localhost:1000/struts2_0500_actionMethod/user/user!sub
这样就可以实现不用很多的action了
-------------------------------------------------------------------------------------------------
UserAction.java
代码:
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
public String add() {
return SUCCESS;
}
}
可以在配饰魏积安中配置Action的时候用method=来制定执行那个方法,
也可以在url地址中动态指定(动态方法调用MDI)
要说明的是:
前者会产生太多的action
如:<action name="user" class="com.b510.hongten.UserAction" method="add">
<result>/user.jsp</result>
</action>
<action neme="user" class="com.b510.hongten.UserAction" method="sub">
<result>/user.jsp</result>
</action>
...
</action>
后者只用一个action就可以做到这些,只是在url中输入方法名即可
<action name="user" class="com.b510.hongten.UserAction">
<result>/user.jsp</result>
</action>
调用的时候我们在url中这样写:
http://localhost:1000/struts2_0500_actionMethod/user/user!add
http://localhost:1000/struts2_0500_actionMethod/user/user!sub
这样就可以实现不用很多的action了
-------------------------------------------------------------------------------------------------
UserAction.java
代码:
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
public String add() {
return SUCCESS;
}
}
相关文章推荐
- struts2配置及ActionMethod_DMI_动态方法调用
- struts2 2.5动态方法调用(DMI) dynamic method invoke 出现不被允许的方法时 Method add for action dynamic is not allowed! - [unknown location]
- struts2 ActionMethod DMI 动态方法调用
- 使用Struts2动态方法调用时(DMI)出现There is no Action mapped for namespace [/user] and action name [user!add] 问题
- struts2动态方法调用 ActionName!methodName.action
- struts2 DMI用感叹号动态调用方法时提示there is no action mapped for
- Struts2中DMI(动态方法调用)的错误问题(There is no Action mapped for namespace [/xxx] and action name [xxx!yyy] a)
- struts2中使用DMI(动态调用方法)方式配置action
- 动态方法调用 在Struts2中动态方法调用有三种方式,动态方法调用就是为了解决一个Action对应多个请求的处理,以免Action太多 第一种方式:指定method属性 这种方式我们前面已经用到过
- struts2学习 - action -3 动态方法调用 DMI
- struts2中使用DMI(动态调用方法)方式配置action
- Struts2 ActionMethod 【DMI】(动态方法调用 Dynamic Method Invoke)
- Struts2关于Action的系统训练4关于动态方法调用DMI
- ActionMethod 动态方法调用(DMI)
- Struts2自定义Action,自定义方法,DMI(动态方法调用),路径问题
- Struts2-动态方法调用-Could not find action or result-Method update for action user is not allowed
- Struts2基础之四:动态方法调用(DMI)和action通配符
- struts2动态方法调用 ActionName!methodName.action
- Struts2在动态调用Action的方法时的错误
- Struts2的动态调用Action方法和默认Action