Webwork基本原理

Webwork基本原理

概要分析一下流程

 

  1. Web.xml

webwork

com.opensymphony.webwork.dispatcher.FilterDispatcher

 

webwork

/*

 

com.opensymphony.webwork.dispatcher.FilterDispatcher,从这里开始了webwork2之旅[by gaoling]

 

 

  1. FilterDispatcher.doFilter
  • Request.parameter->map

ActionMapping mapping = mapper.getMapping(request);

  • du.serviceAction(request, response, servletContext, mapping);

将控制权交给DispatcherUtils

 

  1. DispatcherUtils
  • 这里定义了ActionProxy

ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, name, extraContext, true, false);

  • 然后调用了proxy.execute();

 

下面到了xwork部分

 

  1. com.opensymphony.xwork.DefaultActionProxy[by gaoling]

retCode = invocation.invoke();

// invocation:com.opensymphony.xwork.DefaultActionInvocation

 

 

  1. com.opensymphony.xwork.DefaultActionInvocation

看看invocation.invoke();方法

 

if (interceptors.hasNext()) {//执行拦截器

InterceptorMapping interceptor = (InterceptorMapping) interceptors.next();

            //递归到invocation.invoke();下面我们看看是如何实现递归的。
//关键在下面一句话,interceptor.getInterceptor()会返回一个com.opensymphony.xwork.interceptor.Interceptor,Interceptor.interceptinvocation)方法调用了result = invocation.invoke();[by gaoling]

resultCode = interceptor.getInterceptor().intercept(this);

} else {

            //当所有的拦截器执行完毕后,执行invokeActionOnly

resultCode = invokeActionOnly();

}

 

  1. invokeActionOnly

invokeActionOnly这个函数会反射到我们的action中,执行我们的业务逻辑代码

return (String) method.invoke(action, new Object[0]);

 

 

  1. 执行完业务逻辑代码,回到上面的递归

再看invocation.invoke()方法:

if (!executed) {

if (preResultListeners != null) {

for (Iterator iterator = preResultListeners.iterator();

iterator.hasNext();) {

PreResultListener listener = (PreResultListener) iterator.next();

listener.beforeResult(this, resultCode);

}

}

 

// now execute the result, if we're supposed to

if (proxy.getExecuteResult()) {

executeResult();//返回result

}

 

executed = true;

}

 

  1. executeResult();

result.execute(this);

Represents a generic interface for all action execution results, whether that be displaying a webpage, generating an email, sending a JMS message, etc.

 

#上面只是很粗浅的分析,下一步看看webwork2是如何处理request,action,配置映射,result等细节问题的。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值