`

struts选择拦截某些方法

 
阅读更多
public abstract class MethodFilterInterceptor extends AbstractInterceptor {  
    protected transient Logger log = LoggerFactory.getLogger(getClass());  
      
    protected Set<String> excludeMethods = Collections.emptySet();  
    protected Set<String> includeMethods = Collections.emptySet();  
 
    public void setExcludeMethods(String excludeMethods) {  
        this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);  
    }  
      
    public Set<String> getExcludeMethodsSet() {  
        return excludeMethods;  
    }  
 
    public void setIncludeMethods(String includeMethods) {  
        this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods);  
    }  
      
    public Set<String> getIncludeMethodsSet() {  
        return includeMethods;  
    }  
 
    @Override 
    public String intercept(ActionInvocation invocation) throws Exception {  
        if (applyInterceptor(invocation)) {  
            return doIntercept(invocation);  
        }   
        return invocation.invoke();  
    }  
 
    protected boolean applyInterceptor(ActionInvocation invocation) {  
        String method = invocation.getProxy().getMethod();  
        // ValidationInterceptor  
        boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method);  
        if (log.isDebugEnabled()) {  
            if (!applyMethod) {  
                log.debug("Skipping Interceptor... Method [" + method + "] found in exclude list.");  
            }  
        }  
        return applyMethod;  
    }  
      
    /**  
     * Subclasses must override to implement the interceptor logic.  
     *   
     * @param invocation the action invocation  
     * @return the result of invocation  
     * @throws Exception  
     */ 
    protected abstract String doIntercept(ActionInvocation invocation) throws Exception;  
      
}  


<!--使用拦截器-->
            <interceptor-ref name="defaultStack"></interceptor-ref> 
            <interceptor-ref name="FilterInterceptor"> 
<!--拦截器黑白名单-->
                 <param name="includeMethods">method1</param> 拦截
                 <param name="excludeMethods">method2</param> 不拦截
<!--指定参数name的值-->
<param name="name">FilterMethod</param>
            </interceptor-ref> 
分享到:
评论

相关推荐

    理解拦截器用于在某个方法或字段被访

    拦截器,在AOP(Aspect-Oriented Programming)中用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加入某些操作。拦截是AOP的一种实现策略。 在Webwork的中文文档的解释为——拦截器是动态拦截Action调用...

    struts2的核心.拦截器(拦截器的实现与定义让你轻松入门)

    如果这段代码只在这一两个处需要,我们采取这种办法,还说的过去,但是如果系统对这段代码过于依赖,也就是这段代码在系统中出现的过多,如果那一天我们发现这段代码中在某些地方还需要完善,我们是不是要着个修改...

    ajax请求拦截器

    struts2在struts2.xml里配置拦截器可以过滤到指定的url的请求,但是对于ajax的请求确是过滤不了,比如说sesion超时或某些页面有权限控制的,通过ajax的请求时系统会报错最近在解决此类问题时碰上了找了不少资料,...

    Struts2 Convention Plugin中文文档 Annotion

    翻译:石太祥 Introduction 从struts2.1版本开始,Convention Plugin作为...无需配置Convention即可使用Convention,Convention的某些约束习惯可以通过配置属性来控制,您也可以在类中覆写其中的方法 来达到扩展目地

    struts2注解详细说明

    com.example.actions.products.Index进行处理)无需配置Convention即可使用Convention,Convention的某些约束习惯可以通过配置属性来控制,您也可以在类中覆写其中的方法来达到扩展目地。 安装使用Convention插件,...

    个人知识管理系统 Struts2.0 + Spring + Hibernate

    用户可建立自己的知识分类,对于私密信息(比喻日记等)可增加访问权限,只有登陆用户才能看到,非登陆用户只能浏览公开信息,以及增加新的信息,但无权修改以删除信息,用户权限拦截采用了Struts2的自定义拦截器 ...

    个人知识管理系统 Struts2 + Spring + Hibernate

    用户可建立自己的知识分类,对于私密信息(比喻日记等)可增加访问权限,只有登陆用户才能看到,非登陆用户只能浏览公开信息,以及增加新的信息,但无权修改以删除信息,用户权限拦截采用了Struts2的自定义拦截器 ...

    个人信息管理系统Struts2 spring hibernate dwr

    用户可建立自己的知识分类,对于私密信息(比喻日记等)可增加访问权限,只有登陆用户才能看到,非登陆用户只能浏览公开信息,以及增加新的信息,但无权修改以删除信息,用户权限拦截采用了Struts2的自定义拦截器 ...

    Express+Nodejs 下的登录拦截实现代码

    原来一直不知道怎么在Express+Nodejs里面添加类似于Struts2的拦截器(因为要使用登录拦截的功能)。 以前一直以为在router这块添加类似一下的转移路由控制权代码的(每个都加很麻烦) app.get('/show', ...

    使用Annotation和拦截器实现访问控制 (2010年)

    访问控制是Web应用系统中的主要问题之一。基于数据库和基于配置文件两种...Interceptor(拦截器)是Struts2的一个强有力的工具,用于在某个方法或字段被访问之前进行拦截,然后在之前或之后加入某些操作,它是AOP(Aspect-O

    ch_DreamMarket

    服务层使用作为Struts2拦截器来执行绑定动作类的对象。 MySql数据库用于存储用户数据,包括他们的购物车数据,帐户信息和某些行为。 使用 克隆此存储库或将其下载到本地存储库中。 建议使用MyEclipse在任何IDE中...

    spring security 参考手册中文版

    25.1 AOP联盟(MethodInvocation)安全拦截器 197 25.1.1显式MethodSecurityInterceptor配置 197 25.2 AspectJ(JoinPoint)安全拦截器 198 26.基于表达式的访问控制 200 26.1概述 200 26.1.1通用内置表达式 201 ...

    webx3框架指南PDF教程附学习Demo

    • Struts • Webwork • Tapestry • Spring MVC 以上框架都是非常优秀的。说实话,如果阿里巴巴网站在2001年开始,就有这么多可选择的话,无论选择哪一个都不会有问题。因为这些年来,所有的开源Web框架都在...

Global site tag (gtag.js) - Google Analytics