spring拦截器配置
来源:互联网 发布:mac ps 序列号 编辑:程序博客网 时间:2024/05/24 06:40
拦截器的实现分3个步骤:
1,定义实现上述接口的拦截器类(com.opensymphony.xwork2.interceptor.Interceptor 或者继承AbstractInterceptor)
2,在struts.xml中定义这个拦截器
3,在需要使用拦截器的Action中引用拦截器
2.
代码:
public class LoginInterceptor implements Interceptor{private static final long serialVersionUID = 1L;public void destroy() {}public void init() {}public String intercept(ActionInvocation invocation) throws Exception {System.out.println("进入拦截器");(拦截器相关的操作) String re = invocation.invoke();return null;}在Struts中配置:
<interceptors>
<interceptor name="actionIntercept" class="interceptor.LoginInterceptor"></interceptor>
</interceptors>
同时可以拦截器栈进行一组拦截器的配置:
<interceptor-stack name="systemInterceptorStack">
<interceptor-ref name="userAuthorityInterceptor" />
<interceptor-ref name="exceptionInterceptor" />
</interceptor-stack>
此放在<interceptors></interceptors>之间,在所含有的拦截器之后。
拦截器的配置范围:
1.某一个action中
<action name="login" class="login" method="login">
<result name="success">success.jsp</result>
<interceptor-ref name="actionIntercept"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref> 如果使用拦截器则必须添加默认的拦截器
</action>
2.全局拦截器
将拦截器定义在一个包下:
<package name="all" extends="struts-default">
<interceptors>
<!-- 定义权限控制拦截器 -->
<interceptor name="authority"
class="akai.cost.ms.base.AuthInterceptor" />
<!-- 定义一个包含权限控制的拦截器栈 -->
<interceptor-stack name="mydefault">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="authority" />
</interceptor-stack>
</interceptors>
<!-- 定义默认拦截器 -->
<default-interceptor-ref name="mydefault" />(包下的拦截器)
</package>
其他的包继承这个包:
- spring拦截器配置
- spring拦截器配置
- spring拦截器配置
- Spring 拦截器配置
- spring拦截器配置
- Spring配置拦截器
- spring 拦截器配置
- spring拦截器配置
- Spring拦截器配置事务
- spring mvc 拦截器配置
- spring mvc 拦截器配置
- Spring boot配置拦截器
- Spring +Mybatis 拦截器配置
- Spring Boot配置拦截器
- Spring Boot配置拦截器
- Spring 配置拦截器 HandlerInterceptor
- Spring Boot拦截器配置
- spring注解配置拦截器
- 清水设计表现~~~专业承接家装,工装效果图制作~~~
- C语言中,栈的操作
- 尤尼科技首推3D打印机使用教材 助力3D打印基础教育产业
- java socket单线程阻塞IO
- java 用poi框架读取excel 2010
- spring拦截器配置
- 网络基于NGN/IMS(SIP协议)通信平台融入视频监控业务
- 基本社会里模型的源码分析
- 全角字符unicode码对应表
- 基于Virtex系列FPGA的可编程嵌入式信号处理背板的设计
- 24_C# 实现VMS客户端——控件_布局设计
- ADI 15款常用的运算放大器的对比学习
- JS数组方法汇总 array数组元素的添加和删除
- (《剑指Offer》笔记)顺时针打印矩阵