struts2-15自定义拦截器
来源:互联网 发布:免费网络加速器 编辑:程序博客网 时间:2024/05/22 06:09
自定义拦截器:
自定义拦截器需要实现com.opensymphony.xwork2.interceptor.Interceptor接口:
public class PermissionInterceptor implements Interceptor{ public void destroy(){} public void init(){} public String intercept(ActionInvocation invocation) throws Excetion{ sysout.out.print("进入拦截器......"); if(session中存在用户){ String result = invocation.invoke(); }else{ return "login"; } }}
<package name="test" namespace="/control/test" extends="struts-default"> <interceptors> <interceptor name="permission" class="cn.gz.interceptor.PermissionInterceptor"/> <interceptor-stack name="permissionStack"> <interceptor-ref name="defaultStack"/> <interceptor-ref name="permission" /> </interceptor-stack> </interceptors> <global-results> <result name="success">/WEB-INF/page/message.jsp</result> </global-results> <action name="list_*" class="cn.gz.action.HelloWorldAction" method="{1}"> <interceptor-ref name="permissionStack" /> </action> </package>
因为struts2中的如文件上传、数据校验、封装请求参数到action等功能都是由系统默认的defaultStack中的拦截器实现的,所以我们自定义的拦截器需要引用系统默认的defaultStack,这样运用才可以使用struts2框架提供的众多功能。如果希望包下的所有action都使用自定义的拦截器,可以通过<default-interceptor-ref name = "permissionStack"/>把拦截器定义为默认拦截器,备注:每个包只能定义一个默认拦截器,另外,一旦我们为该包的某个action显示指定了某个拦截器,则默认拦截器就不会起作用了。
阅读全文
0 0
- struts2-15自定义拦截器
- struts2 自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- struts2自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- struts2自定义拦截器
- Struts2---自定义拦截器
- struts2自定义拦截器
- struts2自定义拦截器
- Struts2自定义拦截器
- struts2自定义拦截器
- struts2自定义拦截器
- struts2自定义拦截器
- struts2自定义拦截器
- Groovy基础
- tf.control_dependencies与tf.identity组合详解
- 深度学习引论(三):损失函数、BP算法
- EastUi验证
- IC卡读写
- struts2-15自定义拦截器
- C# 调用 WebServices 接口
- Ubuntu发布重要更新将修复九个漏洞
- PMBOK笔记 第1章 引论 (2)
- CTS测试框架 -- 基础框架启动
- C# 对 Win Form 窗口按钮禁用
- ubuntu下MySQL的安装使用与卸载-程序编译
- 大数据推荐系统实时架构和离线架构
- 记录mysql操作日志