interceptor 拦截器
2015-12-17 18:07
281 查看
<?xml version="1.0" encoding= "UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name ="struts.devMode" value= "true"></constant >
<constant name= "struts.enable.DynamicMethodInvocation" value= "true"></constant >
<package name ="test" namespace="/" extends= "struts-default">
<!-- 定义一个权限控制拦截器 -->
<interceptors >
<interceptor name ="authority" class= "com.cola.interceptor.AuthorizationInterceptor" ></interceptor >
</interceptors >
<!-- 定义一个全球结果集处理方式,所有经过拦截器的action都会按下面处理跳转 -->
<global-results >
<result name ="login">/login.jsp</ result>
</global-results >
<action name ="test" class= "com.cola.action.TestAction" method ="execute">
<result name ="success" type= "dispatcher">/test.jsp</result >
<!-- 使用拦截器 -->
<interceptor-ref name= "defaultStack"></interceptor-ref >
<interceptor-ref name= "authority"></interceptor-ref >
</action >
</package >
<include file ="struts2.xml"></ include>
</struts>
--------------------------------------------------
package com.cola.interceptor;
import java.util.Map;
import com.cola.bean.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
@SuppressWarnings("all" )
public class AuthorizationInterceptor implements Interceptor{
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void init() {
// TODO Auto-generated method stub
}
@Override
public String intercept(ActionInvocation ai) throws Exception {
Map<String,Object> session = ai.getInvocationContext().getSession();
User user = (User) session.get( "user");
if( user!= null){
return ai.invoke();
}
return Action. LOGIN;
}
}
相关文章推荐
- PHPMailer使用说明
- [Java异常]ClassNotFoundException in Java
- Objective-c语言_NSDate(时间类型)和NSCalendar(日历)和NSTimeZone(时区)
- property_get函数使用
- http://weng851217.blog.163.com/blog/static/884996120101128102441359/
- nginx的那些内置变量
- Hackers top in China
- loadJS
- DataXceiver error processing unknown operation src: /127.0.0.1:36479 dst: /127.0.0.1:50010处理
- Wix打包系列(一)如何使用wix制作安装程序
- iOS FFmpeg实时YUV420P编码H264
- 第十二周项目一----图基本算法库
- Docker Swarm
- page request session application四种范围
- CAPI&CAPICOM的一些知识[转]
- 12-转盘
- Maven系列--pom.xml 配置详解
- mac vim 配置文件
- 对拍
- Handler Thread