Struts2工作流程结袍 (1)客户端提交一个( HttpservletreqUest)请求 (2)请求被提交到一系列(主要是3层)的过滤器( Filter),如 ( Action ContextCleanUp、其他过滤器( Site Mesh等)、 FilterDispatcher)。注意:这里是有顺序的,先是 Action Context CleanUp,再是其他过滤器( Site mesh等),最后到 FilterDispatchero (3) FilterDispatcher接收到请求后,询问 ActionMapper是否需要调用 某个 Action来处理这个( Http servletrEquest)请求,如果 ActionMapper决定需要调用某个 Action, FilterDispatcher则把请求的处 理交给 Action Proxy (4) Action Proxy通过 Configuration Manager( struts. xml)询问框架的 配置文件,找到需要调用的 Action类(该 Action类一般是程序员自定义 的处理请求的类)。 (5) Action Proxy创建一个 ActionInvocation( Action的调用者)实例, 同时 ActionInvocation通过代理模式调用 Action。但在调用之前, ActionInvocation会根据配置加载 Action相关的所有 Interceptor(拦截 器) (6)一旦 Action执行完毕, ActionInvocation根据 struts. xm中的配置找 到对应的返回结果 result。然后根据结果返回对应的视图呈现给客户端 (JSP、 FreeMarker等)
Struts 2工作流程结构 (1)客户端提交一个(HttpServletRequest)请求。 (2)请求被提交到一系列(主要是3层)的过滤器(Filter),如 (ActionContextCleanUp、其他过滤器(SiteMesh等)、 FilterDispatcher)。注意:这里是有顺序的,先是ActionContext CleanUp,再是其他过滤器(SiteMesh等),最后到FilterDispatcher。 (3)FilterDispatcher接收到请求后,询问ActionMapper是否需要调用 某个Action来处理这个(HttpServletRequest)请求,如果 ActionMapper决定需要调用某个Action,FilterDispatcher则把请求的处 理交给 ActionProxy。 (4)ActionProxy通过Configuration Manager(struts.xml)询问框架的 配置文件,找到需要调用的Action类(该Action类一般是程序员自定义 的处理请求的类)。 (5)ActionProxy创建一个ActionInvocation(Action的调用者)实例, 同时ActionInvocation通过代理模式调用Action。但在调用之前, ActionInvocation会根据配置加载Action相关的所有Interceptor(拦截 器)。 (6)一旦Action执行完毕,ActionInvocation根据struts.xml中的配置找 到对应的返回结果result。然后根据结果返回对应的视图呈现给客户端 (JSP、FreeMarker等)
Struts2 sequence Struts 拦器⊥ 拦 截器2 Action Result Intercept Intercept execute execute
Struts2 sequence
Action Mapper a Action Mapping org. apache. struts2 dispatcher mapper. Action Mapper接口在 HTTP请求和action调用请求之间提供了一个映射。当给定 个HTP请求时, Action Mapper根据请求的URI来查找是 否有对应的 action调用, 如果有,则返回一个描述了 action调用的 Action Mapper; ·如果没有匹配的 action调用请求,则返回nul Struts框架对该接口提供的默认实现是 org. apache struts2 dispatcher. mapper. DefaultAction Mapper
ActionMapper和ActionMapping org.apache.struts2.dispatcher.mapper.ActionMapper接口在 HTTP请求和action调用请求之间提供了一个映射。当给定 一个HTTP请求时,ActionMapper根据请求的URI来查找是 否有对应的action调用, 如果有,则返回一个描述了action调用的ActionMapper; 如果没有匹配的action调用请求,则返回null. Struts2框架对该接口提供的默认实现是 org.apache.struts2.dispatcher.mapper.DefaultActionMapper
Action Proxy Fp ActionInvocation Action Proxy在 WOrk中和真正的 Action充当代理的角色 在通过框架执行 Action的过程中,因为是使用代理而不是 直接操纵对象,所以可以在代理中封装拦截器、等额外代 码 Action Proxy持有 Actioninvocation对象。 ActionInvocation 代表了 action执行的当前状态
ActionProxy和ActionInvocation ActionProxy在XWork中和真正的Action充当代理的角色, 在通过框架执行Action的过程中,因为是使用代理而不是 直接操纵对象,所以可以在代理中封装拦截器、等额外代 码。 ActionProxy持有ActionInvocation对象。ActionInvocation 代表了action执行的当前状态
Struts2的处理流程 用户请求 Filter Dispatcher Interceptor Struts2内置的一些拦截器或用户自定义拦截器 Action 用户编写的 action类,类似 struts中的 Action Result 类似 Struts中的 Forward 响应 Jsp/html FilterDispatcher是 Struts2框架的核心控制器,它负责拦截由<url- pattern>/*</ url-pattern>指定的所有用户请求,当用户请求到达时,该 Filter会过滤用户的请求。默认情况下,如果用户请求的路径不带后缀或者 后缀以 action结尾,这时请求将被转入 Struts2框架处理,否则 Struts2框架 将略过该请求的处理。当请求转入 Struts2框架处理时会先经过一系列的拦 截器,然后再到 Action
Struts2的处理流程 FilterDispatcher Interceptor Action Result Jsp/html 用户请求 Struts2内置的一些拦截器或用户自定义拦截器 用户编写的action类,类似struts1中的Action 类似struts1中的forward 响应 FilterDispatcher是Struts 2框架的核心控制器,它负责拦截由<url- pattern>/*</url-pattern>指定的所有用户请求,当用户请求到达时,该 Filter会过滤用户的请求。默认情况下,如果用户请求的路径不带后缀或者 后缀以.action结尾,这时请求将被转入Struts 2框架处理,否则Struts 2框架 将略过该请求的处理。当请求转入Struts 2框架处理时会先经过一系列的拦 截器,然后再到Action