struts2拦截器
来源:互联网 发布:联通电信网络转换 编辑:程序博客网 时间:2024/06/05 16:31
Struts2开始使用convention-plugin来实现struts的零配置。
零配置并不是没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少。
原理:它采用了java动态代理和反射的机制来实现。
二、Interceptor的接口里的intercept方法是实现整个拦截器机制的核心方法,它所依赖的参数ActionInvocation是Action调度者。
一个很重要的方法invocation.invoke()。
这个方法具备以下2层含义:
1. 如果拦截器堆栈中还有其他的Interceptor,那么invocation.invoke()将调用堆栈中下一个Interceptor的执行。
2. 如果拦截器堆栈中只有Action了,那么invocation.invoke()将调用Action执行。
三、API
//取得session
Map session = actionInvocation.getInvocationContext().getSession();
String actionName = invocation.getInvocationContext().getName();//获取请求名称
String className = invocation.getAction().getClass().getName();//处理请求的Action
String namespace = invocation.getProxy().getNamespace();//请求名前的命名空间
【总结】拦截器只能拦截Action的,而filter是可以过滤所有的东西的;
自定义的拦截器要实现Interceptor接口,ActionInvocation的invoke()就类似于filter的dofilter();
四、打开struts-default.xml文件,在最下面我们可以看到
<default-interceptor-ref name="defaultStack"/>
该配置说明Struts默认使用的拦截器栈是defaultStack。
如果在struts.xml里配置了它,此默认interceptor是针对所有action的;
零配置并不是没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少。
<constant name="struts.convention.result.path" value="/WEB-INF/page" /><constant name="struts.convention.package.locators" value="web,action" />一、struts2中的拦截器是一个有用的功能,使用它我们可以在一系列业务操作之前或之后做一些特定的操作,比如常见的权限控制。
原理:它采用了java动态代理和反射的机制来实现。
二、Interceptor的接口里的intercept方法是实现整个拦截器机制的核心方法,它所依赖的参数ActionInvocation是Action调度者。
一个很重要的方法invocation.invoke()。
这个方法具备以下2层含义:
1. 如果拦截器堆栈中还有其他的Interceptor,那么invocation.invoke()将调用堆栈中下一个Interceptor的执行。
2. 如果拦截器堆栈中只有Action了,那么invocation.invoke()将调用Action执行。
三、API
//取得session
Map session = actionInvocation.getInvocationContext().getSession();
String actionName = invocation.getInvocationContext().getName();//获取请求名称
String className = invocation.getAction().getClass().getName();//处理请求的Action
String namespace = invocation.getProxy().getNamespace();//请求名前的命名空间
【总结】拦截器只能拦截Action的,而filter是可以过滤所有的东西的;
自定义的拦截器要实现Interceptor接口,ActionInvocation的invoke()就类似于filter的dofilter();
四、打开struts-default.xml文件,在最下面我们可以看到
<default-interceptor-ref name="defaultStack"/>
该配置说明Struts默认使用的拦截器栈是defaultStack。
如果在struts.xml里配置了它,此默认interceptor是针对所有action的;
0 0
- 【Struts2】Struts2中拦截器
- struts2拦截器
- Struts2拦截器
- struts2.0拦截器
- struts2.0 拦截器
- struts2拦截器学习
- struts2 拦截器
- Struts2拦截器(Interceptor)
- struts2.0拦截器
- 用上struts2拦截器
- struts2拦截器简介
- Struts2:拦截器概述
- Struts2拦截器(Interceptor)
- struts2 拦截器
- 关于struts2拦截器
- Struts2的拦截器
- struts2拦截器
- Struts2拦截器总结
- 负载均衡
- Swift中使用CocoaPods
- 微信网页授权设置回调域名
- 生成验证码
- x264框架概览
- struts2拦截器
- 使用WebSocket实现图文直播功能
- Javascript-网页编程-DHTML-下拉菜单
- LeetCode 1.Two Sum ------------LeetCode 第一题
- sqlplus 上下左右及回退乱码
- 调用系统的相册、相机、闪光灯,可以选择相册的照片
- suspend_stress linux 版本
- 基于Spring解决jsp传值乱码问题 get post
- VS2010 c#创建及调用Webservice