Struts2 Action下面的Method调用方法
2014-09-01 14:38
543 查看
1. 在struts.xml中加入<constant name="struts.enable.DynamicMethodInvocation" value="true" /> 来打开struts中的DMI功能,调用方法为userAction!add
解决使用Struts2.3.16 出现There is no Action mapped for namespace [/user] and action name [user!add] associated with context path错误。
2. 使用通配符
Struts2配置文件中使用通配符收藏
形式一:调用相同Action中的不同方法
<action name="*Action" class="Jcuckoo.LoginRegistAction" method="{1}"> <result name="input">/login.jsp</result> <result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result> </action>
其中表达式{1}的值name属性值中第一个*的值。
如果用户请求的URL为loginAction.action,则调用Jcuckoo.LoginRegistAction中的login方法; 如果用户请求的URL为registerAction.action,则调用Jcuckoo.LoginRegistAction中的register方法;
形式二:通过匹配,调用不同的Action的execute方法
<action name="*Action" class="Jcuckoo.{1}Action"> <result name="input">/login.jsp</result> <result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result> </action>
上面没有出现method属性,故默认调用对应的execute方法
如果用户请求的URL为LoginAction.action,则调用Jcuckoo.LoginAction中的execute方法; 如果用户请求的URL为RegisterAction.action,则调用Jcuckoo.RegisterAction中的execute方法;
形式三:动态结果
<action name="crud_*" class="Jcuckoo.CrudAction" method="{1}"> <result name="input">/input.jsp</result> <result>/{1}.jsp</result> </action>
当处理结果是input时,会转到/input.jsp页面
2014年执业医师资格考试 医学综合笔试 临床执业医师 口腔执业医师 中医执业医师
当处理结果是success时,
如果crud_create.action,则会执行Jcuckoo.CrudAction中的create方法,并且跳转到/create.jsp; 如果crud_delete.action,则会执行Jcuckoo.CrudAction中的delete方法,并且跳转到/delete.jsp;
解决使用Struts2.3.16 出现There is no Action mapped for namespace [/user] and action name [user!add] associated with context path错误。
2. 使用通配符
Struts2配置文件中使用通配符收藏
形式一:调用相同Action中的不同方法
<action name="*Action" class="Jcuckoo.LoginRegistAction" method="{1}"> <result name="input">/login.jsp</result> <result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result> </action>
其中表达式{1}的值name属性值中第一个*的值。
如果用户请求的URL为loginAction.action,则调用Jcuckoo.LoginRegistAction中的login方法; 如果用户请求的URL为registerAction.action,则调用Jcuckoo.LoginRegistAction中的register方法;
形式二:通过匹配,调用不同的Action的execute方法
<action name="*Action" class="Jcuckoo.{1}Action"> <result name="input">/login.jsp</result> <result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result> </action>
上面没有出现method属性,故默认调用对应的execute方法
如果用户请求的URL为LoginAction.action,则调用Jcuckoo.LoginAction中的execute方法; 如果用户请求的URL为RegisterAction.action,则调用Jcuckoo.RegisterAction中的execute方法;
形式三:动态结果
<action name="crud_*" class="Jcuckoo.CrudAction" method="{1}"> <result name="input">/input.jsp</result> <result>/{1}.jsp</result> </action>
当处理结果是input时,会转到/input.jsp页面
2014年执业医师资格考试 医学综合笔试 临床执业医师 口腔执业医师 中医执业医师
当处理结果是success时,
如果crud_create.action,则会执行Jcuckoo.CrudAction中的create方法,并且跳转到/create.jsp; 如果crud_delete.action,则会执行Jcuckoo.CrudAction中的delete方法,并且跳转到/delete.jsp;
相关文章推荐
- 动态方法调用 在Struts2中动态方法调用有三种方式,动态方法调用就是为了解决一个Action对应多个请求的处理,以免Action太多 第一种方式:指定method属性 这种方式我们前面已经用到过
- struts2中调用action中的方法method只能是无参的方法
- struts2动态方法调用 ActionName!methodName.action
- Struts2-动态方法调用-Could not find action or result-Method update for action user is not allowed
- struts2动态方法调用 ActionName!methodName.action
- struts2 ActionMethod DMI 动态方法调用
- struts2 2.5动态方法调用(DMI) dynamic method invoke 出现不被允许的方法时 Method add for action dynamic is not allowed! - [unknown location]
- Struts2 ActionMethod DMI(动态方法调用)
- struts2配置及ActionMethod_DMI_动态方法调用
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- struts2:动态方法调用与通配符定义action
- Struts2如何调用Action的方法
- Struts2 Action多方法调用
- struts2动态方法调用和使用通配符定义action
- Struts2 Action多方法调用
- struts2教程:10、动态方法调用和使用通配符定义action
- Struts2使用通配符完成方法和action的调用
- struts2动态方法调用和使用通配符定义action
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- struts2 action配置时 method 省略不写 默认执行方法是什么?