首页 > 代码库 > struts2 DMI
struts2 DMI
在使用DMI(动态方法调用)的时候要注意struts.xml配置时要把
?
1 | <constant name= "struts.enable.DynamicMethodInvocation" value=http://www.mamicode.com/ "true" /> |
不然会出现错误
完整示例代码
struts.xml
<constant name="struts.devMode" value="http://www.mamicode.com/true" /> <constant name="struts.enable.DynamicMethodInvocation" value="http://www.mamicode.com/true"/> <package name="default" namespace="/path" extends="struts-default"> <action name="path" class="com.pengli.structs2.actionstudy.IndexAction3"> <result name ="a"> /MyPath.jsp </result> </action> </package> <package name="default2" namespace="/" extends="struts-default"> <action name="path2" class="com.pengli.structs2.actionstudy.IndexAction3"> <result name ="a"> /MyPath.jsp </result> <result name ="add"> /hello.jsp </result> <result name ="edit"> /index.jsp </result> </action> </package>
IndexAction3
package com.pengli.structs2.actionstudy; import com.opensymphony.xwork2.ActionSupport; public class IndexAction3 extends ActionSupport{ @Override public String execute() throws Exception { // TODO Auto-generated method stub return "a"; } public String add() { return "add"; } public String edit() { return "edit"; } }
web.xml
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。