struts2的ActionProxy接口分析

来源:互联网 发布:网络电视看电视台软件 编辑:程序博客网 时间:2024/06/01 08:17

        ActionProxy是XWork和要执行的action之间额外的一层,如此一来就可以使用不同的代理。比如,可以

使用远程代理,例如RMI或SOAP等

        ActionProxyFactory用来生成ActionProxy代理的实例(工厂模式)。

        ActionProxy接口的默认实现类是DefaultActionProxy(下面是部分代码)。该最重要的是execute方法,

方法最重要的作用是调用ActionInvocation实例的invoke方法,从而进入struts2框架的拦截器进行拦截处

理和调用action方法

public class DefaultActionProxy implements ActionProxy, Serializable {    public String execute() throws Exception {        ActionContext nestedContext = ActionContext.getContext();        ActionContext.setContext(invocation.getInvocationContext());        String retCode = null;        String profileKey = "execute: ";        try {        UtilTimerStack.push(profileKey);                    retCode = invocation.invoke();//调用ActionInvocation实例的invoke方法,进行拦截器的处理或action方法        } finally {            if (cleanupContext) {                ActionContext.setContext(nestedContext);            }            UtilTimerStack.pop(profileKey);        }        return retCode;    }}




0 0
原创粉丝点击