Struts的DMI(动态调用)

动态方法调用:DMI -- dynamic Method invoke
*在action类中定义多个方法:public String xxx(){xxx}
extends ActionSupport{
public String [color=red]execute[/color](){
System.out.println("execute~~~");
return "ok";
}
public String [color=red]login[/color](){
System.out.println("login");
return "loginok";
}
public String [color=red]queryAllUser[/color](){
System.out.println("all users");
return "queryAllok";
}
public String [color=red]updateUser[/color](){
System.out.println("update user");
return "updateok";
}
}
*在struts.xml中配置action:
<action [color=red]name="emp_*" method="{1}"[/color] class="com.c32.multiple.methods.action.MultipleMethodDMIAction">
<result name="loginok">/index.jsp</result>
<result name="queryAllok">/index.jsp</result>
<result name="updateok">/index.jsp</result>
</action>
*注意:1.[color=red]由于action的name为【emp_*】,且其中的【*】是可以匹配任意多个任意字符的通配符[/color],所以
如下url:
http://localhost:8989/appname/dmi/[color=red]emp_[/color]login
http://localhost:8989/appname/dmi/emp_queryalluser
http://localhost:8989/appname/dmi/emp_updateUser
都可以匹配到name为【emp_*】的action
2.【method="{1}"】中的【{1}】是一个占位符,【emp_*】中的【*】匹配到的内容会填充
到【{1}】的位置上
3.所以如下的url,可以访问到的action类,及action类中的可执行的方法为:
http://localhost:8989/appname/dmi/emp_login-->MultipleMethodDMIAction中login方法
http://localhost:8989/appname/dmi/emp_queryalluser-->MultipleMethodDMIAction中queryalluser方法
http://localhost:8989/appname/dmi/emp_updateUser-->MultipleMethodDMIAction中updateUser方法
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值