struts2中自定义拦截器intercept的相关配置及使用方法
2017-03-25 22:07
483 查看
使用自定义的拦截器
继承其中的两个类较为方便:
MethodFilterInterceptor
该类有两个可以设置是拦截具体方法,这是AbstractInterceptor所不具备的,使用只需要在struts.xml中静态注入参数即可
setIncludeMethods(String includeMethods):设置需要拦截的方法,多个方法用逗号分隔
setExcludeMethods(String excludeMethods):设置不需要拦截的方法,多个方法用逗号分隔
例如伪代码:
<action name="名称" class="动作类全名">
<param name="拦截器类名.excludeMethods">方法名</param>
</action>#即该拦截器不拦截该方法
AbstractInterceptor
继承其中的两个类较为方便:
MethodFilterInterceptor
该类有两个可以设置是拦截具体方法,这是AbstractInterceptor所不具备的,使用只需要在struts.xml中静态注入参数即可
setIncludeMethods(String includeMethods):设置需要拦截的方法,多个方法用逗号分隔
setExcludeMethods(String excludeMethods):设置不需要拦截的方法,多个方法用逗号分隔
例如伪代码:
<action name="名称" class="动作类全名">
<param name="拦截器类名.excludeMethods">方法名</param>
</action>#即该拦截器不拦截该方法
@Override public String doIntercept(ActionInvocation invocation) throws Exception { //放行 String s = invocation.invoke(); // 返回的逻辑视图 return s; }
AbstractInterceptor
@Override public String intercept(ActionInvocation invocation) throws Exception { //放行 String s = invocation.invoke(); // 返回的逻辑视图 return s; }例如伪代码:
如果该类需要一些动作方法跳过拦截,则需要在struts.xml中的需要拦截的动作方法 <action name="需要拦截的方法" class="动作方法的类全名"> <intercept-ref name="defaultStack"></intercept-ref> <intercept-ref name="自定义拦截器配置的名称"></intercept-ref> </action>
相关文章推荐
- struts2自定义拦截器注解配置方法
- Struts2 自定义拦截器配置和使用
- 在struts2中配置自定义拦截器放行多个方法
- struts2拦截器-自定义拦截器,放行某些方法(web.xml配置)
- Struts2为应用指定多个配置文件和动态方法调用以及通配符的使用方法
- Struts2使用12 -- 拦截器2 -- 配置
- struts2自定义验证规则及配置使用
- struts2中配置文件的常量使用方法
- 电商项目笔记之一:复杂一些的struts2配置(自定义拦截器)
- struts2 已有拦截器使用以及自定义拦截器使用
- Struts2 自定义拦截器(方法拦截器)
- Struts2使用20 -- 注解配置2 -- 生命周期回调注解(拦截器注解)
- 传智播客--struts2.x的常量配置,动态方法调用,通配符,拦截器,ValueStack和标签
- Struts2拦截器属性excludeMethods、includeMethods配置无效之解决方法
- struts2拦截器的配置和使用
- Struts2 自定义拦截器(方法拦截器)
- UltraVNC远程控制软件相关使用配置方法详解(附图)
- 使用struts2自定义拦截器,要引入defaultStack
- Struts2中配置全局拦截器的方法
- struts2关于action拦截器使用方法 现记录如下