java自定义拦截器


1.创建拦截器处理类

(1)继承AbstranctInterceptor类

(2)重写intercept方法

 

2.配置struts.xml文件

 1 <!-- 定义拦截器的集合 -->
 2         <interceptors>
 3             <!-- 定义拦截器 -->
 4             <interceptor name="logInterceptor" class="cn.bing.interceptor.LogInterceptor"></interceptor>
 5             <!-- 定义拦截器栈 -->
 6             <interceptor-stack name="myStack">
 7                 <!-- 1. 引用默认的拦截器栈,让struts2默认的拦截器栈先执行,从而是实现Strtus2的常用功能正常使用 -->
 8                 <interceptor-ref name="defaultStack"></interceptor-ref>
 9                 <!-- 2. 引用自定义的拦截器-->
10                 <interceptor-ref name="logInterceptor"></interceptor-ref>
11             </interceptor-stack>
12         </interceptors>
13         <!-- 调用自定义的拦截器栈 -->
14         <default-interceptor-ref name="myStack"></default-interceptor-ref>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM