struts2中MethodFilterInterceptor类的用法
来源:互联网 发布:淘宝卖零食需要执照吗 编辑:程序博客网 时间:2024/06/01 11:49
这个拦截器用于拦截部分函数。
拦截器类
package com.test.interceptor;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;public class FunctionInterceptor extends MethodFilterInterceptor{@Overrideprotected String doIntercept(ActionInvocation invocation) throws Exception {System.out.println("FunctionInterceptor拦截器之前。。。。。。。。。。。");String result=invocation.invoke();System.out.println("FunctionInterceptor。。。。。。。。。。拦截器之后。");return result;}}
struts.xml配置
<?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.enable.DynamicMethodInvocation" value="true" /> <constant name="struts.devMode" value="true" /> <package name="default" namespace="" extends="struts-default"> <!-- 这里是拦截器的配置 --> <interceptors> <interceptor name="test" class="com.test.interceptor.TestInterceptor"></interceptor> <!-- 用于仅拦截某些方法 --> <interceptor name="function" class="com.test.interceptor.FunctionInterceptor"> <param name="includeMethods">add</param> </interceptor> <interceptor-stack name="myStack"> <interceptor-ref name="test"/> <interceptor-ref name="function"/> <interceptor-ref name="defaultStack"/> </interceptor-stack> </interceptors> <!-- 正确和错误的分别跳转,input是在验证失败后会跳转的页面 --> <action name="data" class="com.test.action.ValideAction"> <interceptor-ref name="myStack"></interceptor-ref> <!-- 使用拦截器的动作 --> <result name="success">/result.jsp</result> <result name="input">/login.jsp</result> </action> <action name="FunctionInterceptor" class="com.test.action.ValideAction" method="add"> <interceptor-ref name="myStack"></interceptor-ref> <!-- 使用拦截器的动作 --> <result name="success">/result.jsp</result> <result name="input">/login.jsp</result> </action> <action name="dele" class="com.test.action.ValideAction" method="dele"> <interceptor-ref name="myStack"></interceptor-ref> <!-- 使用拦截器的动作 --> <result name="success">/result.jsp</result> <result name="input">/login.jsp</result> </action> </package></struts>
主要是这样一段代码:
<interceptor name="function" class="com.test.interceptor.FunctionInterceptor">
<param name="includeMethods">add</param>
</interceptor>
说明拦截的方法只有add,不拦截其他方法。
0 0
- struts2中MethodFilterInterceptor类的用法
- Struts2-MethodFilterInterceptor
- struts2的拦截器(5):继承MethodFilterInterceptor抽象类实现拦截方法的拦截器
- Struts2中的MethodFilterInterceptor
- Struts2中的MethodFilterInterceptor
- Struts2中的MethodFilterInterceptor
- SSH-Struts2简单的自定义拦截器MethodFilterInterceptor
- MethodFilterInterceptor
- struts2中#$%的用法
- Struts2——MethodFilterInterceptor--方法拦截器
- AbstractInterceptor和MethodFilterInterceptor的区别
- struts2中namespace的用法
- struts2 中 annotation的用法
- Struts2中namespace的用法
- Struts2中namespace的用法
- Struts2中namespace的用法
- struts2 标签中¥%#的用法
- Struts2中namespace的用法
- maven
- iframe 背景透明问题
- [BZOJ 1050&&HAOI 2006]旅行comf
- 新书推荐:《Liferay Portal 6.1门户网站建设最佳实践》
- iOS项目bug总结
- struts2中MethodFilterInterceptor类的用法
- CentOS6.5下使用NetHogs监控进程网络使用情况
- 推荐一本学习IOS开发的书籍
- Spring集成struts2
- break continue
- 考虑使用JavaConfig替代XML配置
- linux安装php
- HttpClient 使用详解
- php获取数组中重复数据