Struts2-12 Struts2运行流程分析

Struts2运行流程图如下所示:

这里写图片描述

Struts2请求的处理步骤概述:

  1. 客户端发送请求;
  2. 请求经过一系列过滤器(Filter),起主要作用的是StrutsPrepareAndExecuteFilter过滤器(另有可选过滤器ActionContextCleanUp用于和其他框架集成);
  3. 调用FilterDispatcher,用于询问 ActionMapper当前该请求是否为Struts2请求(即是否返回一个非空的ActionMapping对象);
  4. 若ActionMapper认为该请求为Struts2请求,则FilterDispatcher将请求交给ActionProxy处理;
  5. ActionProxy通过Configuration Manager访问框架的配置文件,确定需要调用的Action 类及Action方法;
  6. ActionProxy创建一个ActionInvocation的实例,并对其进行初始化;
  7. ActionInvocation实例在调用Action的过程前后,涉及到相关拦截器(Intercepter)的调用;
  8. Action执行完毕,ActionInvocation负责根据struts.xml中的配置找到对应的返回结果;调用结果的execute()方法以渲染结果,渲染过程中可以使用Struts2框架所提供的标签;
  9. 执行各个拦截器invocation.invoke()之后的代码,并返回结果到客户端。

附:相关API

  • ActionMapping:Simple class that holds the action mapping information used to invoke a Struts action. The name and namespace are required.
  • ActionMapper:When given an HttpServletRequest, the ActionMapper may return null if no action invocation request matches, or it may return an ActionMapping that describes an action invocation for the framework to try.
  • ActionProxy:ActionProxy is an extra layer between XWork and the action so that different proxies are possible.
  • ActionInvocation:An ActionInvocation represents the execution state of an Action. It holds the Interceptors and the Action instance. By repeated re-entrant execution of the invoke() method, initially by the ActionProxy, then by the Interceptors, the Interceptors are all executed, and then the Action and the Result.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值