首页 > 其他 > 详细

Struts2的动态调用action方法

时间:2014-10-27 06:59:38      阅读:188      评论:0      收藏:0      [点我收藏+]

动态调用action方法,是指用 action!method 格式的请求来请求后台的逻辑处理    


 前提条件:在struts.xml或者struts.properties中配置

                  struts.enable.DynamicMethodInvocation常量为true ,否则动态调用不可用      


查看源码:      在org.apache.struts2.dispatcher.mapper.DefaultActionMapper中

    

protected ActionMapping parseActionName(ActionMapping mapping)
    {
        if(mapping.getName() == null)
            return null;
        //该参数即struts.enable.DynamicMethodInvocation常量的值,
        //因此设为true,才可以用动态调用请求action
        if(allowDynamicMethodCalls)
        {
            String name = mapping.getName();
            int exclamation = name.lastIndexOf("!");
            if(exclamation != -1)
            {
                mapping.setName(name.substring(0, exclamation));
                mapping.setMethod(name.substring(exclamation + 1));
            }
        }
        return mapping;
    }

注意:通配符格式的action请求与参数struts.enable.DynamicMethodInvocation的值无关

Struts2的动态调用action方法

原文:http://wangyaojie.blog.51cto.com/8877058/1568272

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