Struts2运行流程分析

本文详细解析了Struts2的运行流程,包括从请求发送给StrutsPrepareAndExecuteFilter开始,直至渲染结果并发送到客户端的全过程。重点介绍了ActionMapper、ActionProxy、ActionInvocation等核心组件的工作机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.Struts2运行流程图:

二.运行流程分析:

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

ActionMappingSimpleclass that holds the action mapping information used to invoke a Struts action.The name and namespace arerequired
ActionMapperWhengiven anHttpServletRequest, theActionMapper mayreturn null if no action invocation request matches, or it may return anActionMapping thatdescribes an action invocation for the framework totry
ActionProxyActionProxy isan extra layer betweenXWork andthe action so that different proxies are possible.
ActionInvocationAnActionInvocation 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 theActionProxy,then by the Interceptors, the Interceptors are all executed, and then the Action and the Result.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值