Struts2请求过程原理分析
2015-05-02 20:00
232 查看
1.org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter()方法中
DefaultActionInvocation.invoke()
首先会顺序的递归执行当前Action中所配置的所有的拦截器, 直到拦截器遍历完毕调用真正的Action
通过调用DefaultActionInvocation的invokeActionOnly()方法去反射调用Action, 过程中, 会从当前的invocation对象中得到Action的实例, 并通过代理对象获得配置信息.
5.com.opensymphony.xwork2.DefaultActionInvocation.invokeAction()方法:
反射获得当前请求分发的Action中的方法对象
以传入的Action实例反射调用该处理方法
如果返回的结果不是com.opensymphony.xwork2.Result的实例, 返回强转为字符串的结果.
6.回到1.4所在方法继续:
将invokeAction返回的resultCode存储到当前的invokeAction实例中
进入result处理
7.com.opensymphony.xwork2.DefaultActionInvocation.executeResult()方法:
创建result对象(com.opensymphony.xwork2.DefaultActionInvocation.createResult()方法)
如果当时调用Action返回了Result对象, 则直接返回
否则, 通过proxy对象获取配置信息, 根据resultCode获取到Result对象
使用ognl翻译result中的用${}和%{}标识引用ValueStack中的值的参数.
调用执行result
8.org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute()方法
准备执行环境: request, pageContext等等
判断有没有合适的分发器, 如果没有, 发404消息
在request对象中设定两个属性:
struts.view_uri: 分发之后的url地址
struts.request_uri: 真正请求的url地址
发送真正的响应信息
9.至此, Action的处理完毕, 回归到1.4.1中指明的递归调用那里, 逐步的返回并执行每个拦截器的invokeAction.invoke()后面的代码, 从这里也就可以看出拦截器的机制.
c
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 { //首先会顺序的递归执行当前Action中所配置的所有的拦截器, 直到拦截器遍历完毕调用真正的Action resultCode = interceptor.getInterceptor().intercept(DefaultActionInvocation.this); } finally { UtilTimerStack.pop(interceptorMsg); } } else { //通过调用DefaultActionInvocation的invokeActionOnly()方法去反射调用Action, 调用过程中, 会从当前的invocation对象中得到Action的实例, // 并通过代理对象获得配置信息. resultCode = invokeActionOnly(); }
DefaultActionInvocation.invoke()
首先会顺序的递归执行当前Action中所配置的所有的拦截器, 直到拦截器遍历完毕调用真正的Action
通过调用DefaultActionInvocation的invokeActionOnly()方法去反射调用Action, 过程中, 会从当前的invocation对象中得到Action的实例, 并通过代理对象获得配置信息.
5.com.opensymphony.xwork2.DefaultActionInvocation.invokeAction()方法:
反射获得当前请求分发的Action中的方法对象
以传入的Action实例反射调用该处理方法
如果返回的结果不是com.opensymphony.xwork2.Result的实例, 返回强转为字符串的结果.
6.回到1.4所在方法继续:
将invokeAction返回的resultCode存储到当前的invokeAction实例中
进入result处理
7.com.opensymphony.xwork2.DefaultActionInvocation.executeResult()方法:
创建result对象(com.opensymphony.xwork2.DefaultActionInvocation.createResult()方法)
如果当时调用Action返回了Result对象, 则直接返回
否则, 通过proxy对象获取配置信息, 根据resultCode获取到Result对象
使用ognl翻译result中的用${}和%{}标识引用ValueStack中的值的参数.
调用执行result
8.org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute()方法
准备执行环境: request, pageContext等等
判断有没有合适的分发器, 如果没有, 发404消息
在request对象中设定两个属性:
struts.view_uri: 分发之后的url地址
struts.request_uri: 真正请求的url地址
发送真正的响应信息
9.至此, Action的处理完毕, 回归到1.4.1中指明的递归调用那里, 逐步的返回并执行每个拦截器的invokeAction.invoke()后面的代码, 从这里也就可以看出拦截器的机制.
c
相关文章推荐
- struts2请求过程源码分析
- struts2请求过程源码分析
- struts2请求过程源码分析(转)
- struts2请求过程源码分析
- struts2请求过程源码分析
- struts2请求过程源码分析(转载学习)
- asp.net中webservice请求发送原理和过程的初步分析[原]
- struts2请求过程源码分析
- struts2请求处理过程源代码分析(1)
- struts2处理请求的过程分析
- struts2请求处理过程源代码分析(2)
- struts2请求过程源码分析
- struts2请求过程源码分析
- struts2的请求处理过程源码分析
- struts2请求过程源码分析
- struts2处理请求的过程分析
- struts2请求过程源码分析
- 结合原生http url请求的过程,分析form即表单提交的原理
- struts2请求过程源码分析
- struts2 请求过程源码分析【精】