首页 > 其他 > 详细

struts2 DMI

时间:2014-06-12 10:33:47      阅读:363      评论:0      收藏:0      [点我收藏+]

在使用DMI(动态方法调用)的时候要注意struts.xml配置时要把

1
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>

不然会出现错误

bubuko.com,布布扣

 

完整示例代码

struts.xml

bubuko.com,布布扣
 <constant name="struts.devMode" value="true" />
 <constant name="struts.enable.DynamicMethodInvocation" value="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>
bubuko.com,布布扣

IndexAction3

bubuko.com,布布扣
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";
    }
}
bubuko.com,布布扣

web.xml

bubuko.com,布布扣
  <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>
bubuko.com,布布扣

 

 

 

struts2 DMI,布布扣,bubuko.com

struts2 DMI

原文:http://www.cnblogs.com/li-peng/p/3782395.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!