1.1.1       ActionInvocation类

ActionInvocation定义为一个接口。主要作用是表现action的运行状态。它拥有拦截器和action的实例。通过重复的运行invoke方法。首先被actionProxy,然后是拦截器,全部拦截器运行完后就是action和result .

图3.3.4 ActionInvocation类的主要方法

1.1.2       DefaultActionInvocation类

DefaultActionInvocation类是ActionInvocation接口的实现类. 一般都用该类实例化ActionInvocation。 基本的方法例如以下:

图3.3.5 DefaultActionInvocation类的主要方法

关键方法:invoke()方法

executed = false; 默觉得false。表示该action还没有运行。

假设运行就会抛出已经运行的异常。

然后推断拦截器是否已经配置,假设配置了拦截器就会从配置信息中获得拦截器配置类InterceptorMapping。

此类中仅仅包括两个属性,一个就是name和interceptor实例。

public String invoke()
throws
Exception {

String profileKey = "invoke: ";

try {

UtilTimerStack.push(profileKey);

if (executed) {

throw
new
IllegalStateException("Action has already executed");

}

//递归运行interceptor

if (interceptors.hasNext())

{          //interceptors是InterceptorMapping实际上是像一个像//FilterChain一样的Interceptor链

//通过调用Invocation.invoke()实现递归牡循环

final InterceptorMapping interceptor =
interceptors.next();

String interceptorMsg = "interceptor: " + interceptor.getName();

UtilTimerStack.push(interceptorMsg);

try {

//在每一个Interceptor的方法中都会return invocation.invoke()

resultCode = interceptor.getInterceptor().intercept(DefaultActionInvocation.this);

}

finally {

UtilTimerStack.pop(interceptorMsg);

}

} else {

//当全部interceptor都运行完,最后运行Action,invokeActionOnly会调用//invokeAction()方法

resultCode = invokeActionOnly();

}

// this is needed because the result will be executed, then control will return to the Interceptor, which will

// return above and flow through again

//在Result返回之前调用preResultListeners

//通过executed控制,仅仅运行一次

if (!executed) {

if (preResultListeners !=
null) {

for (Object preResultListener :
preResultListeners) {

PreResultListener listener = (PreResultListener) preResultListener;

String _profileKey = "preResultListener: ";

try {

UtilTimerStack.push(_profileKey);

listener.beforeResult(this,
resultCode);

}

finally {

UtilTimerStack.pop(_profileKey);

}

}

}

// now execute the result, if we're supposed to

//运行result。

if (proxy.getExecuteResult()) {

executeResult();

}

executed = true;

}

return
resultCode;

}

finally {

UtilTimerStack.pop(profileKey);

}

}

深入struts2.0(七)--ActionInvocation接口以及3DefaultActionInvocation类的更多相关文章

  1. Struts2.0中ActionInvocation使用

    Interceptor的接口定义没有什么特别的地方,除了init和destory方法以外,intercept方法是实现整个拦截器机制的核心方法.而它所依赖的参数ActionInvocation则是我们 ...

  2. Struts2第七篇【介绍拦截器、自定义拦截器、执行流程、应用】

    什么是拦截器 拦截器Interceptor-..拦截器是Struts的概念,它与过滤器是类似的-可以近似于看作是过滤器 为什么我们要使用拦截器 前面在介绍Struts的时候已经讲解过了,Struts为 ...

  3. Struts2.0 封装请求数据和拦截器介绍

    1. Struts2 框架中使用 Servlet 的 API 来操作数据 1.1 完全解耦合的方式 Struts2 框架中提供了一个 ActionContext 类,该类中提供了一些方法: stati ...

  4. Struts2.0笔记二

    Mvc与servlet 1.1   Servlet的优点 1.  是mvc的基础,其他的框架比如struts1,struts2,webwork都是从servlet基础上发展过来的.所以掌握servle ...

  5. 入门struts2.0

    框架是什么? 1.应用程序的半成品. 2.可重用行公共的结构. 3.按一定规则组织的一组组件. model2 其实并不是一种全新的概念,很对人指出model2其实正好是经典的"模型(mode ...

  6. (转)struts2.0配置文件、常量配置详解

    一.配置: 在struts2中配置常量的方式有三种: 在struts.xml文件中配置 在web.xml文件中配置 在sturts.propreties文件中配置 1.之所以使用struts.prop ...

  7. Struts2.0+Spring3+Hibernate3(SSH~Demo)

    Struts2.0+Spring3+Hibernate3(SSH~Demo) 前言:整理一些集成框架,发现网上都是一些半成品,都是共享一部分出来(确实让人很纠结),这是整理了一份SSH的测试案例,完全 ...

  8. Struts2.0 xml文件的配置(package,namespace,action)

    struts.xml配置 struts.xml文件是整个Struts2框架的核心. struts.xml文件内定义了Struts2的系列Action,定义Action时,指定该Action的实现类,并 ...

  9. Struts2.0

    流程详解:   配置详解:   constant  (常用常量配置) 使用Struts2 框架 ,先要导入Struts2 需要的jar 包 , 通过配置中央控制器 以及web.xml 来实现  Str ...

随机推荐

  1. foreach 、 for 换成 ForEach

    List<tBaseRolerMapPower> list =new  List<tBaseRolerMapPower>() string strName = string.E ...

  2. Leetcode 476.数字的补数

    数字的补数 给定一个正整数,输出它的补数.补数是对该数的二进制表示取反. 注意: 给定的整数保证在32位带符号整数的范围内. 你可以假定二进制数不包含前导零位. 示例 1: 输入: 5 输出: 2 解 ...

  3. ACM-ICPC 2018 沈阳赛区网络预赛 J树分块

    J. Ka Chang Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero p ...

  4. 九度oj 题目1443:Tr A

    题目描述: A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973. 输入: 数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n(2 <= n & ...

  5. Android中动态改变控件的大小的一种方法

    在Android中有时候我们需要动态改变控件的大小.有几种办法可以实现  一是在onMeasure中修改尺寸,二是在onLayout中修改位置和尺寸.这个是可以进行位置修改的,onMeasure不行. ...

  6. PHP经典面试题目汇总(上篇)

    1.双引号和单引号的区别 双引号解释变量,单引号不解释变量 双引号里插入单引号,其中单引号里如果有变量的话,变量解释 双引号的变量名后面必须要有一个非数字.字母.下划线的特殊字符,或者用{}讲变量括起 ...

  7. android 脱壳 之 dvmDexFileOpenPartial断点脱壳原理分析

    android 脱壳 之 dvmDexFileOpenPartial断点脱壳原理分析 导语: 笔者主要研究方向是网络通信协议的加密解密, 对应用程序加固脱壳技术很少研究, 脱壳壳经历更是经历少之甚少. ...

  8. 在vue项目当中使用sass

    需要分别安装node-sass 和 sass-loader;可以不需要ruby; webpack当中配置 { test: /\.vue$/, loader: 'vue-loader', options ...

  9. La 3942 字符串+dp

    题目大意:一个字符串,可以分解成若干英语单词的连接(单词可以重复使用),求有多少种方法? #include<iostream> #include<cstdio> #includ ...

  10. 阶乘-递归-java

    public class Main { public static void main(String[] args) { for (int i=0;i<11;i++){ System.out.p ...