日期:2014-05-17  浏览次数:20739 次

struts2流程简单问题(我是初学者)
1、ConfigurationManager 存有配置文件的一些基本信息,ActionMapper存有action的配置信息。
2、过滤器会通过询问ActionMapper类来查找请求中需要用到的Action。
3、ActionProxy通过ConfigurationManager询问框架的配置文件,找到需要调用的Action类。
我想问一下这三句话是不是正确的,如果正确那第一句话的意思就是ConfigurationManager是读取struts.properties,ActionMapper是读取struts.xml。那第三句ActionProxy怎么能是通过ConfigurationManager找到需要调用的Action类呢,干嘛不通过ActionMapper找到需要调用的Action类??

------解决方案--------------------
DefaultActionInvocation下invokeAction方法:
Java code

   protected String invokeAction(Object action, ActionConfig actionConfig) throws Exception {
        String methodName = proxy.getMethod();

        if (LOG.isDebugEnabled()) {
            LOG.debug("Executing action method = " + actionConfig.getMethodName());
        }

        String timerKey = "invokeAction: "+proxy.getActionName();
        try {
            UtilTimerStack.push(timerKey);
            
            Method method;
            try {
                method = getAction().getClass().getMethod(methodName, new Class[0]);
            } catch (NoSuchMethodException e) {
                // hmm -- OK, try doXxx instead
                try {
                    String altMethodName = "do" + methodName.substring(0, 1).toUpperCase() + methodName.substring(1);
                    method = getAction().getClass().getMethod(altMethodName, new Class[0]);
                } catch (NoSuchMethodException e1) {
                    // throw the original one
                    throw e;
                }
            }

            Object methodResult = null;
            if (action instanceof Proxy) {
                try {
                    methodResult = Proxy.getInvocationHandler(action).invoke(action, method, new Object[0]);
                } catch (Throwable throwable) {
                    throwable.printStackTrace();
                    throw new Exception("Error invoking on proxy: " + throwable.getMessage());
                }
            } else {
                methodResult = method.invoke(action, new Object[0]);
            }
            if (methodResult instanceof Result) {
                this.result = (Result) methodResult;
                return null;
            } else {
                return (String) methodResult;
            }
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("The " + methodName + "() is not defined in action " + getAction().getClass() + "");
        } catch (InvocationTargetException e) {
            // We try to return the source exception.
            Throwable t = e.getTargetException();

            if (actionEventListener != null) {
                String result = actionEventListener.handleException(t, getStack());
                if (result != null) {
                    return result;
                }
            }
            if (t instanceof Exception) {
                throw(Exception) t;
            } else {
                throw e;
            }
        } finally {
            UtilTimerStack.pop(timerKey);
        }
    }