有关于Struts2的拦截器的原理

在此共设置了两个拦截器,firstInterception、SecondInterception

 package struts2_inteception;

 public class firstInterception implements Interception{
public void interceptor(ActionInvocaton invocation){
System.out.println("-1");
invocation.invoke();
System.out.println("1"); }
}
 package struts2_inteception;

 public class SecondInterception2 implements Interception{
public void interceptor(ActionInvocaton invocation){
System.out.println("-2");
invocation.invoke();
System.out.println("2"); }
}

主函数Main类

 package struts2_inteception;

 public class Main {
public static void main(String []args){
new ActionInvocaton().invoke();
} }

拦截器接口Interceptor

 package struts2_inteception;

 public interface Interception {
public void interceptor(ActionInvocaton actionInvocaton);
}

一个模拟struts2的Action类

package struts2_inteception;

public class Action {
public void execute(){
System.out.println("execute()方法的执行");
} }

一个ActionInvocation类,

package struts2_inteception;

import java.util.List;
import java.util.ArrayList; public class ActionInvocaton {
int index=-1;
Action action=new Action();
List<Interception> interceptions=new ArrayList<Interception>();
public ActionInvocaton(){
//在此调用一系列的拦截器
this.interceptions.add(new firstInterception());
this.interceptions.add(new SecondInterception2());
}
public void invoke(){
index++;
if (index>=interceptions.size()){
//调用action的方法
action.execute();
}else{
//调用拦截器中加的东西
this.interceptions.get(index).interceptor(this);
} } }

真正的struts2的拦截器执行过程如下:

执行的结果如下:

-1
-2
execute()方法的执行
2
1

Struts2拦截器说明的更多相关文章

  1. Struts2 拦截器配置以及实现

    @(Java ThirdParty)[Struts|Interceptor] Struts2 拦截器配置以及实现 Struts2的拦截器应用于Action,可以在执行Action的方法之前,之后或者两 ...

  2. struts2 拦截器

    拦截器:对Action的访问.可以拦截到Action中某个方法.与过滤器不同,过滤器过滤的是请求.过滤JSP.html.但是拦截器不能拦截jsp.html的访问. Struts2 拦截器在访问某个 A ...

  3. Struts2拦截器的使用 (详解)

    Struts2拦截器的使用 (详解) 如何使用struts2拦截器,或者自定义拦截器.特别注意,在使用拦截器的时候,在Action里面必须最后一定要引用struts2自带的拦截器缺省堆栈default ...

  4. struts2拦截器

    一.自定义拦截器 struts2拦截器类似于servlet过滤器 首先定义一个拦截器这个拦截器实现了Interceptor接口: package cn.orlion.interceptor; impo ...

  5. Struts2拦截器模拟

    前言: 接触Struts2已经有一段时间,Student核心内容就是通过拦截器对接Action,实现View层的控制跳转.本文根据自身理解对Struts2进行一个Java实例的模拟,方便大家理解! 示 ...

  6. Struts2拦截器初涉

    Struts2拦截器初涉 正在练习struts,本例是从一个pdf上摘抄的例子,那本pdf都不知道叫什么名字,不过感觉很适合初学者. 在这里要实现一个简单的拦截器"GreetingInter ...

  7. 浅谈Struts2拦截器的原理与实现

    拦截器与过滤器           拦截器是对调用的Action起作用,它提供了一种机制可以使开发者定义在一个action执行的前后执行的代码,也可以在一个action执行前阻止其执行.同时也是提供了 ...

  8. 基于SSH2框架Struts2拦截器的登录验证实现(转)

        大象在这里假设你已经弄清楚了Struts2拦截器的基本概念,可以进入实际运用了.那么我们在之前的基础上只需要做下小小的改变,就可以使用Struts2的拦截器机制实现登录的验证.     修改数 ...

  9. struts2拦截器interceptor的三种配置方法

    1.struts2拦截器interceptor的三种配置方法 方法1. 普通配置法 <struts> <package name="struts2" extend ...

  10. Struts2拦截器原理以及实例

    一.Struts2拦截器定义 1. Struts2拦截器是在访问某个Action或Action的某个方法,字段之前或之后实施拦截,并且Struts2拦截器是可插拔的,拦截器是AOP的一种实现. 2. ...

随机推荐

  1. 初识rbac

    一.权限组件 1.项目与应用 一个项目可以有多个应用:一个应用可以在多个项目下:前提:应用是组件. 2.什么是权限? 一个包含正则表达式的url就是一个权限. 可以理解为如下方程式: who what ...

  2. 转:ArcInfo数据格式介绍

    ArcInfo常用以下格式的数据:shp.Coverage..Raster CAD和Geodatabase.各种数据的组织形式不一样,其中shp.Coverage.Raster.CAD为文件类型,Ge ...

  3. Android SharedPreferences存储数据

    SharedPreferences是Android中最容易理解的数据存储技术,实际上SharedPreferences处理的就是一个key-value(键值对)SharedPreferences常用来 ...

  4. jQuery判断checkbox是否选中?操作checkbox(不)选中?

    HTML      <form action="">          <input type="checkbox" name="c ...

  5. Android DiskLruCache完全解析,硬盘缓存的最佳方案 --转载

    概述 记得在很早之前,我有写过一篇文章 Android高效加载大图.多图解决方案,有效避免程序OOM,这篇文章是翻译自Android Doc的,其中防止多图OOM的核心解决思路就是使用LruCache ...

  6. submit text3 常用快捷键

    Ctrl+D : 选择单词,重复可增加选择下一个相同的单词 Ctrl+F : 查找内容 Ctrl+G : 跳转到指定行 Ctrl+H : 替换 Ctrl+J : 合并行(已选择需要合并的多行时) Ct ...

  7. IOS 集成友盟分享

    #import <Foundation/Foundation.h> @interface UMSocialSinaHandler : NSObject +(void)openSSOWith ...

  8. Python 变量交换

    # coding = utf-8 a, b = 1, 2 print 'before change' print a, b a, b = b, a print 'after change' print ...

  9. 记忆化搜索,FatMouse and Cheese

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1107 http://acm.hdu.edu.cn/showpro ...

  10. memset赋初值的运用

    int ”较“的原则:加法不爆. 极大值:0x7f 较大值:0x3f 较小值:0xc0 极小值:0x80 long long ”较“的原则:加法不爆. 极大值:0x7f 较大值:0x3f 较小值:0x ...