Struts2添加拦截器
1.struts.xml的配置
<!-- 后台拦截器 --> <package name="authpkg" extends="struts-default" namespace=""> <interceptors> <!-- 定义拦截器 --> <interceptor name="authority" class="com.syxp.yjxx.core.auth.AuthorityInterceptor" /> <!-- 定义拦截器栈 --> <interceptor-stack name="authStack"> <!-- 将拦截器加入默认的拦截器栈中 --> <interceptor-ref name="authority"> <!-- 定义不使用拦截器的方法 --> <param name="excludeMethods">login</param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> </interceptor-stack> </interceptors> <default-interceptor-ref name="authStack" /> <!-- 定义拦截器的全局变量,跳转路径 --> <global-results> <result name="login" type="redirect">/index.jsp</result> </global-results> </package>
2. 拦截器类com.syxp.yjxx.core.auth.AuthorityInterceptor
/** * AuthorityInterceptor.java * * 功能:登录验证拦截器 * 类名:AuthorityInterceptor * * ver 变更日 部门 开发者 变更内容 * ───────────────────────────────────────────────────── * V1.00 2013-11-07 研发部 常宝龙 初版 * * Copyright (c) 2008, 2013 Infopower corporation All Rights Reserved. */ package com.syxp.yjxx.core.auth; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor; /** * 登录验证拦截器 * * @author 常宝龙 * @version Ver 1.0 2013-11-07 新建 * @since CodingExample Ver 1.0 * */ public class AuthorityInterceptor extends MethodFilterInterceptor{ private static final long serialVersionUID = 3457293729347L; @Override protected String doIntercept(ActionInvocation actionInvocation) throws Exception { Object user = actionInvocation.getInvocationContext().getSession().get("user2"); if(user!=null){ //递归调用拦截器 return actionInvocation.invoke(); }else{ return Action.LOGIN; } } }
3.xml文件中配置好后,需要在其他的action中调用这个拦截器,调用方法如下:
<!-- 报表图(辽宁电网受暴雨影响情况) --> <package name="stormReport" namespace="/stormReport" extends="authpkg"> </package>
在extends选择集成拦截器的包
相关推荐
Struts2拦截器(Interceptor) Struts2拦截器(Interceptor)
Struts2拦截器.ppt Struts2拦截器.ppt Struts2拦截器.ppt
struts2,Interceptor struts2拦截器实例,两套实例,一套是针对单个的action配置的,另一套实例是针对全局的action配置的拦截器interceptor
关于struts2 拦截器的详细的解释及其在开发中对struts2的拦截器的应用和拦截器在框架中的作用.
Struts2拦截器实现权限控制demo,我感觉对初学者还是有一定帮助的
基于struts2的拦截器测试,实现了页面的跳转,中间过程的拦截
struts2拦截器的使用说明文档,配置说明文档。可以看一下
struts2拦截器应用小例子,与大家共分享
NULL 博文链接:https://cmexico.iteye.com/blog/621208
Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序
NULL 博文链接:https://lipeixiaoyu.iteye.com/blog/626707
Struts2拦截器原理分析实例 博文链接:https://zmx.iteye.com/blog/457432
struts2拦截器和验证框架
NULL 博文链接:https://pihai.iteye.com/blog/352287