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. C++ 将string转换成char*字符串

    我们经常会使用C和C++的混合编程,在某些情况下,需要将C++的string,转换成char* 的字符串.下面说两种可行的方法,作为总结. 1. data(); 如: string str=" ...

  2. [git 学习篇]版本回退

    再次修改readme.txt ,并将其提交成功 $ git add readme.txt $ git commit -m "append GPL" [master ] append ...

  3. [错误处理]UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

    Stackoverflow 回答: 将byte类型转化:byte_string.decode('utf-8') Jinja2 is using Unicode internally which mea ...

  4. linux磁盘问题排查

    一.ls $>>ls /data* //查看有无input/output error报错 二.demsg $>>demsg|grep sd 问题盘结果: 三.iostat使用 ...

  5. 关闭webkit浏览器的自动完成,修正,大写

    关闭input自动完成<input name="q" type="text" autocomplete="off"/>关闭整个表 ...

  6. [POI2007]MEG-Megalopolis (树状数组,Dfs序)

    题目描述 Solution 这道题考试的时候竟然没有仔细想,结果只拿了暴力分... 其实就是一个 DFS序+树状数组. 我们先把用 DFS 把它变成一个序列,同时记录它们的 \(siz\). 那么我们 ...

  7. gulpfile.js备份

    var gulp = require('gulp'); var uglify = require('gulp-uglify'); // var rename = require('gulp-renam ...

  8. C#函数多返回值的方法

    C#以前都是不支持多返回值,当需要返回多个值的时候,就会感觉比较麻烦,通常的做法有 1.采用ref,out 关键字返回 2.定义类或者结构体 返回对象 C# 6.0出来了新的语法 Tuple 支付返回 ...

  9. 【CF52C】Circular RMQ(线段树区间加减,区间最值)

    给定一个循环数组a0, a1, a2, …, an-1,现在对他们有两个操作: Inc(le, ri, v):表示区间[le, ri]范围的数值增加v Rmq(le, ri):表示询问区间[le, r ...

  10. 关于记忆力:遵从一些原则,自省增加经验,there is a way out of almost everything

    年轻人记忆力减退的原因不同于老年人,由疾病所引起的占极少数,一般都是由于学习生活等因素造成精神高度紧张或连续用脑过度使神经疲劳所致. 学会科学的分析和考虑问题的方法,对提高记忆力来说是最为首要的. 保 ...