Struts2执行过程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Struts2执行过程相关的知识,希望对你有一定的参考价值。
1.
2.
3.
4.
2.Struts执行流程
2.1 web.xml中 StrutsPrepareAndExecuteFilter类
2.2 找到doFilter方法
体现出一种设计模式
解释了Struts2中 request 并不是HttpServletRequest
request = prepare.wrap(包装)Request(request);
***:ActionMapping mapping = prepare.findActionMapping(request, response, true);
findActionMapping方法:
public ActionMapping findActionMapping() {
//先看内存中有没有映射结果!
ActionMapping mapping = (ActionMapping) request.getAttribute(STRUTS_ACTION_MAPPING_KEY);
//没有,找到ActionMapper构建
if (mapping == null || forceLookup) {
mapping = dispatcher.getContainer().getInstance(ActionMapper.class).
}
return mapping;
}
2.3 上面代码已经保证mapping不是null
if (mapping == null) {
} else {
//code execute
execute.executeAction(request, response, mapping);
}
executeAction方法原型如下:
public void executeAction() throws ServletException {
dispatcher.serviceAction(request, response, mapping);
}
*serviceAction原型
public void serviceAction(){
ActionProxy proxy = getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
namespace, name, method, extraContext, true, false);
}
*:寻找ActionInvocation
if (mapping.getResult() != null) {
Result result = mapping.getResult();
result.execute(proxy.getInvocation():返回值类型是ActionInvocation);
} else {
proxy.execute();
}
以上是关于Struts2执行过程的主要内容,如果未能解决你的问题,请参考以下文章