讲几个问题:

1. ActionProxy是因为想做一个代理。使得action可以成为一个webservice或soap对象。

 

 

2.ActionProxy里有ActionInvocation对象,而ActionInvocation里也有ActionProxy。这很有趣。

 

3.当一个Action有一组Intecerpter里,它的调用ActionInvocation非常有意思。Intercerpter里注入调用者自己。这里有一个ArroundIntercepter的递归调用,非常有意思:

 

   //invoke interceptors
  if (interceptors.hasNext()) {
            Interceptor interceptor = (Interceptor) interceptors.next();
            resultCode = interceptor.intercept(this);
        } else {
            resultCode = invokeAction(getAction(), proxy.getConfig());
        }

     //AroundInterceptor
   public String intercept(ActionInvocation invocation) throws   Exception {
        String result = null;

        before(invocation);
        result = invocation.invoke();
        after(invocation, result);

        return result;
     }

 

 

4.执行过程对异常信息处理的过程。事实上,

//sended error.

 

try {
            ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
            request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack());
            proxy.execute();
            // If there was a previous value stack then set it back onto the request
            if (stack != null){
                request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY,stack);
            }
        } catch (ConfigurationException e) {
            log.error("Could not find action", e);
            sendError(request, response, HttpServletResponse.SC_NOT_FOUND, e);
        } catch (Exception e) {
            log.error("Could not execute action", e);
            sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
        }

 

// set to request.

 

 try {
            // send a http error response to use the servlet defined error handler
            // make the exception availible to the web.xml defined error page
            request.setAttribute("javax.servlet.error.exception", e);

            // for compatibility
            request.setAttribute("javax.servlet.jsp.jspException", e);

          // send the error response
            response.sendError(code, e.getMessage());
        } catch (IOException e1) {
        }

 

5。为什么在web多线程环境下,每个请求的request不会相互冲突?

 public class ActionContext {
    //~ Static fields/initializers /////////////////////////////////////////////

    static ThreadLocal actionContext = new ActionContextThreadLocal();

 因为sevlectActionContext继承自ActionContext,而ActionContext有一个静态变量 static ThreadLocal actionContext = new ActionContextThreadLocal()。需要了解为什么,它能保证线程变量安程。因为ThreadLocal就能保证。

评论
发表评论

您还没有登录,请登录后发表评论

苏飞
搜索本博客
存档
最新评论