Struts2中的拦截器实现原理
来源:互联网 发布:四驱车跑道知乎 编辑:程序博客网 时间:2024/06/06 01:32
一个Interceptor接口
public interface Interceptor {
void intercept(ActionInvocation invocation);
}
一个ActionInvocation类用于调用拦截器
/**
* 保存着 很多interceptor
* @author Administrator
*
*/
public class ActionInvocation {
List<Interceptor> interceptors = new ArrayList<Interceptor>();
public ActionInvocation(){
interceptors.add(new ParamInterceptor());
interceptors.add(new ConfigInterceptor());
}
private int i = 0;
public void invoke(){
if(i< interceptors.size()){
Interceptor it = interceptors.get(i++);
//调用 方法前
it.intercept(this);
//调用 方法后
}else{
//调用Action中的execute方法
new Action().execute();
}
};
}
Interceptor的实现类
public class ConfigInterceptor implements Interceptor{
public void intercept(ActionInvocation invocation) {
System.out.println("------ConfigFilter----");
invocation.invoke();
}
}
public class ParamInterceptor implements Interceptor{
public void intercept(ActionInvocation invocation) {
System.out.println("------ParamFilter----");
invocation.invoke();
}
}
//main 来调用
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
new ActionInvocation().invoke();
}
}
输出为:
------ParamFilter----
------ConfigFilter----
----action--------
//-------------------------------------------------------------//
其实现原理就像是过滤器的实现一样
- Struts2中的拦截器实现原理
- Struts2拦截器实现原理
- Struts2拦截器的原理与实现
- 模拟实现struts2拦截器原理
- struts2拦截器实现原理案例分析
- Struts2拦截器的原理与实现
- Struts2拦截器实现原理的理解
- Struts2拦截器的原理与实现
- Struts2拦截器的原理与实现
- struts2学习笔记拦截器实现原理
- Struts2拦截器的原理与实现
- Struts2拦截器的原理与实现
- struts2 拦截器的原理和实现
- Struts2拦截器的原理与实现
- Struts2拦截器的原理及实现
- Struts2拦截器原理
- Struts2拦截器原理
- struts2 拦截器原理
- Autoloading Classes(自动加载所需类)
- 【转】GCC的编译流程详解
- WSARecvFrom()
- 关于内存中栈和堆的区别
- 转贴ARM NEON 优化的例子
- Struts2中的拦截器实现原理
- makefile详解
- 发帖回报进度!
- 使用.NET中的XML注释(一) -- XML注释标签讲解
- RMAN备份全集
- python 正则表达式操作指南
- 基于超级电容的太阳能草坪灯设计方案
- 找到了一个网站,内容很多
- 数据库优化与应用程序性能的五个平衡点