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. ...
随机推荐
- 类的方法练习——定义MySQL类
要求: 1.对象有id.host.port三个属性 2.定义工具create_id,在实例化时为每个对象随机生成id,保证id唯一 3.提供两种实例化方式,方式一:用户传入host和port 方式二: ...
- Django组件——forms组件
一.校验字段功能 通过注册用户这个实例来学习校验字段功能. 1.模型:models.py from django.db import models # Create your models here. ...
- html-其他常见标签的使用
b:加粗 s:删除线 u:下划线 i:斜体 per:原样输出 sup:上标 sub:下标 p:段落标签 比br多一行 (CSS) div:自动换行 span:在一行显示 完整代码: <html& ...
- 设置cssrem,设置emmet
1.文件->首选项->设置 2.搜索cssrem-> 点击设置:"cssrem.rootFontSize": 16, 4.emmet
- ArcGIS Geodabase OBJECTID重新初始编号的间接方法
ArcGIS Geodabase OBJECTID为Long型,随着Feature的增加和删除自动编号,均为增加.即删除Feature后,再增加该号码自动只增加不重新编号. 间接方法可以实现重新从1编 ...
- mantis统计报表和图形报表出现乱码问题的解决方法
Mantis 报表中文乱码 1.安装Mantis图表 1.0插件 administrator登录-------管理------插件管理,安装插件 2.上传字体simhei.ttf simsun.tt ...
- [libxml2]_[XML处理]_[使用libxml2的xpath特性修改xml文件内容]
场景: 1.在软件需要保存一些配置项时,使用数据库的话比较复杂,查看内容也不容易.纯文本文件对utf8字符支持也不好. 2.这时候使用xml是最佳选择,使用跨平台库libxml2. 3.基于xpath ...
- 怎样下载YouTube播放列表视频
YouTube上面的视频种类丰富多彩,要是你想利用上面的资源来学习的话,足够你钻研很长时间了.如果你想在YouTube上面学习一门教程,比如Python,通常这些内容一个视频肯定装不下,会分为好多个视 ...
- likelihood(似然) and likelihood function(似然函数)
知乎上关于似然的一个问题:https://www.zhihu.com/question/54082000 概率(密度)表达给定下样本随机向量的可能性,而似然表达了给定样本下参数(相对于另外的参数)为真 ...
- Google TensorFlow 学习笔记一 —— TensorFlow简介
"TensorFlow is an Open Source Software Library for Machine INtenlligence" 本笔记参考tensorflow. ...