struts2的ActionProxy

ctinoProxy的全名是com.opensymphony.xwork2.ActionProxy,

ActionProxy = Action + Proxy,从字面意思来解释:Action的代理。

在Struts中,ActionContext、ActionInvocation、ActionProxy、ActionConfig联系的很紧密。


1

ActionContext<-->ActionInvocation<-->ActionProxy-->ActionConfig

(1.1)从ActionContext对象可以得到ActionInvocation对象

(1.2)从ActionInvocation对象可以得到ActionContext对象

(2.1)从ActionInvocation对象可以得到ActionProxy对象

(2.2)从ActionProxy对象可以得到ActionInvocation对象

(3.1)从ActionProxy对象可以得到ActionConfig对象

在搜索的时候 ,遇到一句描述ActionInvocation和ActionProxy关系的话,感觉非常切中要害:

Essentially, ActionProxy encapsulates how an Action can be obtained. ActionInvocation encapsulates how the Action is executed when a request is invoked.

本质上来,ActionProxy对如何获取Action对象进行了封装,而ActionInvocation对如何执行Action进行了封装。

原话地址:https://struts.apache.org/docs/action-proxy-actionproxy-factory.html

Typically, an ActionProxy will utilize the ActionInvocation to encapsulate the execution of a particular request.

The ActionInvocation determines how an Action is handled: Is it being intercepted? Is there a PreResultListener acting on it?

在上面图中,

ActionConfig,负责从struts.xml文件中读取配置;

ActionSupport,我们自己实现的Action类一般都继承ActionSupport类;

ActionContext,是Action运行的环境,为Action类提供一些信息;

ActionProxy,是如何获取Action;

ActionInvocation是如何执行Action。

上面标的(1)至(4),都能通过ActionProxy来获得:

(1)表示当前Action类在struts.xml文件中对应的<action>标签所在的<package>标签的namespace属性

(2)表示<action>标签的name属性

(3)表示真实的Action类的实例,不是字符串类型,而<action>标签的class属性对应的类的实例化。

(4)<action>标签的method属性

从一些java培训机构的视频来看,ActionProxy实现了URL和真正Action类之间的映射。



1、如何获取ActionProxy对象


1

ActionProxy proxy = invocation.getProxy();

2、如何获取ActionProxy中的值

(1)获取当前<action>所在的命名空间


1

String namespace = proxy.getNamespace();

(2)获取<action>的名字


1

String actionName = proxy.getActionName();

(3)获取Action类的实例


1

Object action = proxy.getAction();

(4)获取<action>执行的方法


1

String method = proxy.getMethod();

(5)得到ActionInvocation和ActionConfig对象


1

2

3

ActionConfig config = proxy.getConfig();

ActionInvocation invocation2 = proxy.getInvocation();

3、ActionProxy的源代码


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

package com.opensymphony.xwork2;

import com.opensymphony.xwork2.config.entities.ActionConfig;

/**

 * ActionProxy is an extra layer between XWork and the action so that different proxies are possible.

 * <p/>

 * An example of this would be a remote proxy, where the layer between XWork and the action might be RMI or SOAP.

 *

 * @author Jason Carreira

 */

public interface ActionProxy {

    /**

     * Gets the Action instance for this Proxy.

     *

     * @return the Action instance

     */

    Object getAction();

    /**

     * Gets the alias name this ActionProxy is mapped to.

     *

     * @return the alias name

     */

    String getActionName();

    /**

     * Gets the ActionConfig this ActionProxy is built from.

     *

     * @return the ActionConfig

     */

    ActionConfig getConfig();

    /**

     * Sets whether this ActionProxy should also execute the Result after executing the Action.

     *

     * @param executeResult <tt>true</tt> to also execute the Result.

     */

    void setExecuteResult(boolean executeResult);

    /**

     * Gets the status of whether the ActionProxy is set to execute the Result after the Action is executed.

     *

     * @return the status

     */

    boolean getExecuteResult();

    /**

     * Gets the ActionInvocation associated with this ActionProxy.

     *

     * @return the ActionInvocation

     */

    ActionInvocation getInvocation();

    /**

     * Gets the namespace the ActionConfig for this ActionProxy is mapped to.

     *

     * @return the namespace

     */

    String getNamespace();

    /**

     * Execute this ActionProxy. This will set the ActionContext from the ActionInvocation into the ActionContext

     * ThreadLocal before invoking the ActionInvocation, then set the old ActionContext back into the ThreadLocal.

     *

     * @return the result code returned from executing the ActionInvocation

     * @throws Exception can be thrown.

     * @see ActionInvocation

     */

    String execute() throws Exception;

    /**

     * Gets the method name to execute, or <tt>null</tt> if no method has been specified (meaning <code>execute</code> will be invoked).

     *

     * @return the method to execute

     */

    String getMethod();

    /**

     * Gets status of the method value‘s initialization.

     *

     * @return true if the method returned by getMethod() is not a default initializer value.

     */

    boolean isMethodSpecified();

    

时间: 2024-08-10 12:28:52

struts2的ActionProxy的相关文章

struts2创建ActionProxy过程

首先new一个map Map<String, Object> extraContext 这个map有如下键值对 这些key都是在ActionContext类中定义 com.opensymphony.xwork2.ActionContext.parameters                    requestMap com.opensymphony.xwork2.ActionContext.session                          sessionMap com.op

struts2框架 转载 精华帖

一.Struts2简介 参考<JavaEE 轻量级框架应用与开发-S2SH> Struts框架是流行广泛的一个MVC开源实现,而Struts2是Struts框架的新一代产品,是将Struts1和WebWork两种技术进行兼容.合并的全新的MVC框架.Struts2框架充分发挥了Struts1和WebWork这两种技术的优势,抛弃原来Struts1的缺点,使得Web开发更加容易. Struts1运行原理:  Struts1工作流程: (1)客户端向Web应用发送请求,请求被核心控制器Action

深入struts2.0(六)--ActionProxy类

1.1     ActionProxy接口以及实现 ActionProxy在struts框架中发挥着非常重要的作用.通过webwork和xwork交互关系图可以看出,它是action和xwork中间的一层. 正因为ActionProxy的存在导致Action调用更加简洁.接下来我们一起研究下这个核心类. 1.1.1       ActionProxy接口方法 图 3.3.1 ActionProxy接口主要方法图 ActionConfig getConfig();该方法主要是获得创建ActionP

Struts2系列:(18)ActionProxy

ActinoProxy的全名是com.opensymphony.xwork2.ActionProxy, ActionProxy = Action + Proxy,从字面意思来解释:Action的代理. 在Struts中,ActionContext.ActionInvocation.ActionProxy.ActionConfig联系的很紧密. ActionContext<-->ActionInvocation<-->ActionProxy-->ActionConfig (1.

Java Struts2 的请求处理流程详解

一.Struts2的处理流程: 客户端产生一个HttpServletRequest的请求,该请求被提交到一系列的标准过滤器(Filter)组建链中(如ActionContextCleanUp:它主要是清理当前线程的ActionContext.Dispatcher,FilterDispatcher主要是通过ActionMapper来决定需要调用那个Action,FilterDispatcher是控制器的核心,也是MVC中控制层的核心组建). 核心控制器组建FilterDispatcher根据Act

struts2请求过程源码分析

Struts2是Struts社区和WebWork社区的共同成果,我们甚至可以说,Struts2是WebWork的升级版,他采用的正是WebWork的核心,所以,Struts2并不是一个不成熟的产品,相反,构建在WebWork基础之上的Struts2是一个运行稳定.性能优异.设计成熟的WEB框架. 我这里的struts2源码是从官网下载的一个最新的struts-2.3.15.1-src.zip,将其解压即可.里面的目录页文件非常的多,我们只需要定位到struts-2.3.15.1\src\core

Struts2原理及简单实例

参考连接: http://blog.csdn.net/laner0515/article/details/27692673/ http://www.cnblogs.com/sobne/articles/5443114.html 一.Struts2原理 设计目标 Struts设计的第一目标就是使MVC模式应用于web程序设计.在这儿MVC模式的好处就不在提了. 技术优势 Struts2有两方面的技术优势,一是所有的Struts2应用程序都是基于client/server HTTP交换协议,The 

Struts2 核心流程

1.Struts2架构图  这是Struts2官方站点提供的Struts 2 的整体结构.  执行流程图 2.Struts2部分类介绍  这部分从Struts2参考文档中翻译就可以了. ActionMapper         ActionMapper其实是HttpServletRequest和Action调用请求的一个映射,它屏蔽了Action对于Request等 java Servlet类的依赖.Struts2中它的默认实现类是DefaultActionMapper,ActionMapper

Struts2运行原理

一个请求在Struts2框架中的处理大概分为以下几个步骤: 1 客户端发送请求:2 这个请求经过一系列的过滤器(Filter)(这些过滤器中有一个叫做ActionContextCleanUp的可选过滤器,这个过滤器对于Struts2和其他框架的集成很有帮助,例如:SiteMesh Plugin)3 接着FilterDispatcher被调用,FilterDispatcher询问ActionMapper来决定这个请是否需要调用某个Action.FilterDispatcher的功能如下: (1)执