Struts2源码深入

来源:互联网 发布:守望先锋 数据查询 编辑:程序博客网 时间:2024/05/18 20:52
 public String invoke() throws Exception {
        String profileKey = "invoke: ";
        try {
            UtilTimerStack.push(profileKey);


            if (executed) {
                throw new IllegalStateException("Action has already executed");
            }


            if (interceptors.hasNext()) {//递归调用拦截器
                final InterceptorMapping interceptor = interceptors.next();
                String interceptorMsg = "interceptor: " + interceptor.getName();
                UtilTimerStack.push(interceptorMsg);
                try {
                                resultCode = interceptor.getInterceptor().intercept(DefaultActionInvocation.this);
                            }
                finally {
                    UtilTimerStack.pop(interceptorMsg);
                }
            } else {
                resultCode = invokeActionOnly();//执行action里的指定方法,并得到返回的字符串
            }


            // this is needed because the result will be executed, then control will return to the Interceptor, which will
            // return above and flow through again
            if (!executed) {
                if (preResultListeners != null) {
                    for (Object preResultListener : preResultListeners) {
                        PreResultListener listener = (PreResultListener) preResultListener;


                        String _profileKey = "preResultListener: ";
                        try {
                            UtilTimerStack.push(_profileKey);
                            listener.beforeResult(this, resultCode);
                        }
                        finally {
                            UtilTimerStack.pop(_profileKey);
                        }
                    }
                }


                // now execute the result, if we're supposed to
                if (proxy.getExecuteResult()) {
                    executeResult();//在这个函数里得到该action方法返回字符串对应要去的页面
                }


                executed = true;
            }


            return resultCode;
        }
        finally {
            UtilTimerStack.pop(profileKey);
        }
    }
0 0
原创粉丝点击