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();
}

posted on 2016-09-28 11:20  -EASY-  阅读(180)  评论(0编辑  收藏  举报

导航