Struts2拦截器说明
有关于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拦截器说明的更多相关文章
- Struts2 拦截器配置以及实现
@(Java ThirdParty)[Struts|Interceptor] Struts2 拦截器配置以及实现 Struts2的拦截器应用于Action,可以在执行Action的方法之前,之后或者两 ...
- struts2 拦截器
拦截器:对Action的访问.可以拦截到Action中某个方法.与过滤器不同,过滤器过滤的是请求.过滤JSP.html.但是拦截器不能拦截jsp.html的访问. Struts2 拦截器在访问某个 A ...
- Struts2拦截器的使用 (详解)
Struts2拦截器的使用 (详解) 如何使用struts2拦截器,或者自定义拦截器.特别注意,在使用拦截器的时候,在Action里面必须最后一定要引用struts2自带的拦截器缺省堆栈default ...
- struts2拦截器
一.自定义拦截器 struts2拦截器类似于servlet过滤器 首先定义一个拦截器这个拦截器实现了Interceptor接口: package cn.orlion.interceptor; impo ...
- Struts2拦截器模拟
前言: 接触Struts2已经有一段时间,Student核心内容就是通过拦截器对接Action,实现View层的控制跳转.本文根据自身理解对Struts2进行一个Java实例的模拟,方便大家理解! 示 ...
- Struts2拦截器初涉
Struts2拦截器初涉 正在练习struts,本例是从一个pdf上摘抄的例子,那本pdf都不知道叫什么名字,不过感觉很适合初学者. 在这里要实现一个简单的拦截器"GreetingInter ...
- 浅谈Struts2拦截器的原理与实现
拦截器与过滤器 拦截器是对调用的Action起作用,它提供了一种机制可以使开发者定义在一个action执行的前后执行的代码,也可以在一个action执行前阻止其执行.同时也是提供了 ...
- 基于SSH2框架Struts2拦截器的登录验证实现(转)
大象在这里假设你已经弄清楚了Struts2拦截器的基本概念,可以进入实际运用了.那么我们在之前的基础上只需要做下小小的改变,就可以使用Struts2的拦截器机制实现登录的验证. 修改数 ...
- struts2拦截器interceptor的三种配置方法
1.struts2拦截器interceptor的三种配置方法 方法1. 普通配置法 <struts> <package name="struts2" extend ...
- Struts2拦截器原理以及实例
一.Struts2拦截器定义 1. Struts2拦截器是在访问某个Action或Action的某个方法,字段之前或之后实施拦截,并且Struts2拦截器是可插拔的,拦截器是AOP的一种实现. 2. ...
随机推荐
- .NET开源工作流RoadFlow-表单设计-隐藏域
隐藏域即<input type="hidden" value=""/>标签:
- 机器学习(一)——K-近邻(KNN)算法
最近在看<机器学习实战>这本书,因为自己本身很想深入的了解机器学习算法,加之想学python,就在朋友的推荐之下选择了这本书进行学习. 一 . K-近邻算法(KNN)概述 最简单最初级的 ...
- 网络威胁防护,Azure 靠的是它?
在当今数字化转型的浪潮中,越来越多的企业希望转型于云.使用云能帮助企业提高工作效率.降低 IT 成本.增强竞争优势,有效推动企业的业务发展.但是,在向云迁移的过程中,基于云的数据中心更有可能被攻击,所 ...
- 缓存溢出Buffer Overflow
缓存溢出(Buffer overflow),是指在存在缓存溢出安全漏洞的计算机中,攻击者可以用超出常规长度的字符数来填满一个域,通常是内存区地址.在某些情况下,这些过量的字符能够作为“可执行”代码来运 ...
- win10与子系统ubuntu之间互访文件
在window10的store里面 搜索ubuntu,下载,可以安装 注意: 初次打开有许多软件都没安装,可以新进行 sudo apt-get update,之后在进行其他的操作 1.下载的子系统ub ...
- startup ORA-00845: MEMORY_TARGET not supported on this system
一台虚拟机跑多个实例时,由于/dev/shm空间不够导致如下报错> startupORA-00845: MEMORY_TARGET not supported on this system解决方 ...
- delphi7 打开project/options 出错
出错提示:Access violation at address 0012F88F. Write of address 0012F88F.然后又提示一条:Access violation at add ...
- 团队合作之Scrum
CCSU小助手 一:开发团队简介 队名:瓜队 组员:钟文兴.周畅.吉刘磊.唐仲勋 宣言:We are a team at any time! 团队项目描述: 内容:“生活在长大”: 目标:为了方便对学 ...
- git作业
第一部分 我的地址:https://github.com/Tohsaka-Rin-ZYJ/123/tree/master 第二部分 我对git的认识: Git是一个开源的分布式版本控制系统,用以有效. ...
- python接口测试-项目实践(五) 实际结果与预期结果对比之 接口对比
五 与开发接口对比 1 分别将三个接口封装成三个函数,传入接口参数,返回提取并处理后的各字段. 拼接字符串作为单独的函数. def api_1(code): 发送请求获取响应 提取响应数据 响应数据转 ...