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. verilog写的LCD1602 显示

    在读本文之前,请先阅读 LCD1602 的 datasheet(百度到处都是) ,熟悉有关的11条指令集. LCD1602的11个指令集链接 http://www.cnblogs.com/aslmer ...

  2. [python篇] [伯乐在线][1]永远别写for循环

    首先,让我们退一步看看在写一个for循环背后的直觉是什么: 1.遍历一个序列提取出一些信息 2.从当前的序列中生成另外的序列 3.写for循环已经是我的第二天性了,因为我是一个程序员 幸运的是,Pyt ...

  3. Oracle实例和数据库区别

          什么是数据库,其实很简单,数据库就是存储数据的一种媒介.比如常用的文件就是一种,在Oracle10G中,数据的存储有好几种.第一种是文件形式,也就是在你的磁盘中创建一批文件,然后在这些文件 ...

  4. ThinkPHP5杂技(一)

    Thinkphp5 assign 传递 " 时 ,前台收到的是 " 和ThinkPHP3.2不一样,3.2收到的是 ”,传递给js时 用的data.replace(new RegE ...

  5. Spring_mvc的搭建以及实现

    Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块.使用 Spring ...

  6. Android线程中使用Toast、dialog、loading

    代码改变世界 Android线程中使用Toast.dialog.loading Loading: Thread t1 = new Thread(new Runnable() { @Override p ...

  7. google chrome & preferences & languages

    google chrome & preferences & languages language settings https://www.google.com/preferences ...

  8. 【bzoj1965】 [Ahoi2005]SHUFFLE 洗牌 欧拉定理

    题目描述 为了表彰小联为Samuel星球的探险所做出的贡献,小联被邀请参加Samuel星球近距离载人探险活动. 由于Samuel星球相当遥远,科学家们要在飞船中度过相当长的一段时间,小联提议用扑克牌打 ...

  9. 刷题总结——小c找朋友(bzoj4264 集合hash)

    题目: Description 幼儿园里有N个小C,两个小C之间可能是朋友也可能不是.所有小C之间的朋友关系构成了一个无向图,这个无向图中有M条边. 园长ATM发现对于两个(不同的)小Ci和j,如果其 ...

  10. zoj 3791 An Easy Game dp

    An Easy Game Time Limit: 2 Seconds      Memory Limit: 65536 KB One day, Edward and Flandre play a ga ...