ActionDispatcher
是行动辅助类,在一个行动调度到一个公共方法。  .这个类是作为一种替代机制,使用DispatchAction及其各种口味和手段, 调度行为可以很容易地提供到任何Action执行,而不必从一个特定的继承超级Action 。实例Action 持有该类的对象,可以根据参数的不同,实现和MappingDispatcherAction、DispatchAction的类似的功能。
实现代码
             protected ActionDispatcher dispatcher
                                = new ActionDispatcher(this, ActionDispatcher.MAPPING_FLAVOR);

             public ActionForward execute(ActionMapping mapping,
                                                                        ActionForm form,
                                                                        HttpServletRequest request,
                                                                        HttpServletResponse response)
                                                     throws Exception {
                     return dispatcher.execute(mapping, form, request, response);
             }
 
new ActionDispatcher(this, ActionDispatcher.MAPPING_FLAVOR) 的时候,可以根据实际需要,指定不同的MAPPING_FLAVOR,实现不同类型的Action功能。
包含:
  • DEFAULT_FLAVOR
  • DISPATCH_FLAVOR
  • MAPPING_FLAVOR
  •  
    1.Struts-config.xml
                    <action path="/actionDispatcher-submit"    
                                    type="org.apache.struts.webapp.dispatch.ActionDispatcherExample"
                                    parameter="actionDispatcherMethod"
                                    name="testForm"
                                    scope="request">
                            <exception key="dispatch.NoSuchMethodException"
                                                 type="java.lang.NoSuchMethodException"
                                                 path="/actionDispatcher.jsp"/>
                            <exception key="dispatch.ServletException"
                                                 type="javax.servlet.ServletException"
                                                 path="/actionDispatcher.jsp"/>
                            <forward name="success" path="/actionDispatcher.jsp"/>
                    </action>
     
    这里的parameter="actionDispatcherMethod" 与DispatcherAction 意义相同
     
    2.Action代码 也与DispatcherAction 例子中代码一致。只多了以下代码
        private ActionDispatcher dispatcher
                                            = new ActionDispatcher(this,
                                                                    ActionDispatcher.DISPATCH_FLAVOR);
            public ActionForward execute(ActionMapping mapping,
                                                                     ActionForm form,
                                                                     HttpServletRequest request,
                                                                     HttpServletResponse response)
                    throws Exception {
                    return dispatcher.execute(mapping, form, request, response);

            }
     
     
    如果没有execute()方法,会出现空白页页面。
     
    1.出现的异常也和LookupDispatcherAction、MappingDispatcherAction 一样。