struts2-10动态方法调用和使用通配符定义action
2017-12-12 15:22
721 查看
动态方法的调用:
如果action中存在多个方法时,可以使用(!+方法名)调用指定的方法。如下:
假如访问上面action的URL路径为:/struts/test/helloworld.action,要访问action中的addGlob()方法,可以这样调用:
如果不想使用动态方法调用,则可以通过常量struts.enable.DynamicMethodInvocation关闭动态方法调用。
使用通配符定义action:
访问addGlob()方法,可以通过这样的URL路径访问:/test/helloworld_addGlob.action
如果action中存在多个方法时,可以使用(!+方法名)调用指定的方法。如下:
package com.gz.action; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class HelloWorldAction { private String mes; private String userName; public String getMessage() { return mes; } public String execute() throws UnsupportedEncodingException { mes = "hello world!"; this.userName = URLEncoder.encode("你好,世界!","UTF-8");//进行编码 return "success"; } public String addGlob() { return "message"; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } }
假如访问上面action的URL路径为:/struts/test/helloworld.action,要访问action中的addGlob()方法,可以这样调用:
/struts/test/helloworld!addGlob.action
如果不想使用动态方法调用,则可以通过常量struts.enable.DynamicMethodInvocation关闭动态方法调用。
<constant name = "struts.enable.DynamicMethodInvocation" value = "false"/>
使用通配符定义action:
<package name="hello" namespace = "/test" extends = "struts-default"> <action name = "helloworld_*" class = "com.gz.action.HelloWorldAction" method = "{1}"> <result name = "success">/WEB-INF/test/message.jsp</result> </action> </package>
public String execute() throws UnsupportedEncodingException { mes = "hello world!"; this.userName = URLEncoder.encode("你好,世界!","UTF-8");//进行编码 return "success"; } public String addGlob() { return "message"; }
访问addGlob()方法,可以通过这样的URL路径访问:/test/helloworld_addGlob.action
相关文章推荐
- struts2教程:10、动态方法调用和使用通配符定义action
- struts2动态方法调用和使用通配符定义action
- struts2中动态方法调用和使用通配符定义Action
- struts2中动态方法调用和使用通配符定义Action
- Struts2_动态方法调用和使用通配符定义action
- struts2动态方法调用和使用通配符定义action
- struts2学习笔记--------动态方法调用和使用通配符定义action
- Struts2动态方法调用和使用通配符定义action
- Struts2 Action中动态方法调用、通配符的使用
- struct2动态方法调用和使用通配符定义action
- 第三章Struts2 Action中动态方法调用、通配符的使用
- 动态方法调用和使用通配符定义action
- Struts2学习笔记(七):动态方法调用和使用通配符定义action
- 第11章 动态方法调用和使用通配符定义action
- struts2:动态方法调用与通配符定义action
- action动态方法调用和使用通配符定义action
- Struts2 Action中动态方法调用、通配符的使用
- 每当使用struts2动态方法调用时,总是出现错误:There is no Action mapped for namespace [/user] and action name [user!add]
- Struts2使用通配符完成方法和action的调用
- struts2中使用DMI(动态调用方法)方式配置action