struts2运行流程分析


一.运行流程图


   

二.相关的几个API

  •  ActionMapping:Simple class that holds the action mapping information used toinvoke a Struts action. The name and namespace are required

  • ActionMapper:When given an HttpServletRequest, the ActionMapper may return nullif no action invocation request matches, or it may return an ActionMapping thatdescribes an action invocation for the framework to try
  • ActionProxy:ActionProxy is an extra layer between XWork and the action so thatdifferent proxies are possible.
  • ActionInvocation:AnActionInvocation represents the execution state of an Action. It holds theInterceptors and the Action instance. By repeated re-entrant execution of theinvoke() method, initially by the ActionProxy, then by the Interceptors, theInterceptors are all executed, and then the Action and the Result.

三. Struts2 运行流程分析

  1.  请求发送给StrutsPrepareAndExecuteFilter
  2. StrutsPrepareAndExecuteFilter 询问 ActionMapper:该请求是否是一个 Struts2 请求,如果该请求是一个struts2请求,则返回一个非空的ActionMappping对象;如果不是一个struts2请求,则直接执行过。
  3.  若 ActionMapper 认为该请求是一个 Struts2 请求,则 StrutsPrepareAndExecuteFilter 把请求的处理交给 ActionProxy
  4.  ActionProxy 通过 Configuration Manager 询问框架的配置文件,确定需要调用的Action 类及 Action 方法
  5.  ActionProxy 创建一个 ActionInvocation 的实例,并进行初始化
  6.  ActionInvocation 实例在调用Action的过程前后,涉及到相关拦截器(Intercepter)的调用。
  7.  Action 执行完毕,ActionInvocation 负责根据 struts.xml 中的配置找到对应的返回结果。调用结果的 execute 方法,渲染结果。在渲染的过程中可以使用Struts2 框架中的标签。
  8.  执行各个拦截器 invocation.invoke() 之后的代码
  9.  把结果发送到客户端

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值