Struts2中配置全局拦截器的方法
来源:互联网 发布:数据采集卡驱动 编辑:程序博客网 时间:2024/05/18 03:42
在struts.xml中添加如下配置:
<!-- 配置全局拦截器 -->
<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" />
<!-- 定义全局处理结果 -->
<global-results>
<!-- 逻辑名为login的结果,映射到/login.jsp页面 -->
<result name="login">/login.jsp</result>
</global-results>
</package>
使用方法:其他包继承这个包名就可以了
<package name="abc" extends="all" namespace="/">
附:拦截器类
package akai.cost.ms.base;import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class AuthInterceptor extends AbstractInterceptor{@Overridepublic String intercept(ActionInvocation invocation) throws Exception {HttpSession session = ServletActionContext.getRequest().getSession();String userName = (String)session.getAttribute("System_UserName");if(userName == "" || userName == null){//错误,回到登录界面return Action.LOGIN;}else{return invocation.invoke();}}}
- Struts2中配置全局拦截器的方法
- Struts2中配置全局拦截器的方法
- Struts2中配置全局拦截器的方法
- Struts2全局拦截器的配置
- struts2中拦截器的全局拦截和自定义拦截
- Struts2全局拦截器配置
- Struts2拦截器的使用(详解) ----全局配置
- 配置struts2全局拦截器、全局变量
- Struts2全局拦截器
- Struts2中拦截器的配置
- struts2中自定义拦截器的配置
- Struts2拦截器、拦截器栈(Interceptor Stack)、全局拦截器与方法拦截器
- struts2 全局拦截器,显示请求方法和参数
- struts拦截器配置,以及全局的拦截器配置
- struts2拦截器的配置
- struts2 拦截器的配置
- 配置struts2的拦截器
- Struts2拦截器的配置
- php防盗链网站图片采集
- Linux获取本机IP
- ASP.NET MVP架构的浅显理解
- 悟透javascript
- 短信锚的调用
- Struts2中配置全局拦截器的方法
- Activity 生命周期设置
- TCP/IP(一)
- VC++的编译错误信息让人很迷惑啊
- How to Rock an Algorithms Interview
- 使用eclipse生成文档(javadoc)
- 成为编程巨星的唯一秘诀
- TCP/IP(二)
- python 中的 chr ord和repr