Struts2的动态调用action方法

动态调用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的值无关

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章