自己写拦截器, 要认识下面接口 与 类
com.opensymphony.xwork2.interceptor.Interceptor
接口
这是最重要的接口, 一般不直接使用它.
com.opensymphony.xwork2.interceptor.AbstractInterceptor
抽象类(空实现了Interceptor接口)
自己写拦截器 可继承这个抽象类, 重写intercept()方法. 实现对某个Action的拦截
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
抽象
类 (继承AbstractInterceptor)
自己写拦截器 可继承这个抽象类, 重写doIntercept()方法. 实现对某个Action的的某个方法的拦截.
excludeMethods(排除哪方法),includeMethods(拦截哪些方法), 多个方法名用豆号隔开.
<interceptor-ref name="myInterceptor3">
<param name="excludeMethods">test,execute</param>
<param name="includeMethods">test</param>
</interceptor-ref>
-----------------------------------
自定义拦截器 :MyInterceptor
package ssh.org.interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
/**
* 自定义拦截器,实现Interceptor接口
*
* 要是改为继承 AbstractInterceptor 抽象类, 下面destroy(),init()方法就这用写了
*/
public class MyInterceptor implements Interceptor
{
@Override
public void destroy()
{
// TODO Auto-generated method stub
}
@Override
public void init()
{
// TODO Auto-generated method stub
}
@Override
public String intercept(final ActionInvocation actioninvocation) throws Exception
{
System.out.println("方法执行前插入 代码");
//执行目标方法 (调用下一个拦截器, 或执行Action)
final String res = actioninvocation.invoke();
System.out.println("方法执行后插入 代码");
return res;
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="struts-default">
<interceptors>
<!-- 配置自己的拦截器 -->
<interceptor name="myInterception" class="ssh.org.interceptor.MyInterceptor"/>
<!-- 配置自己的拦截器栈 -->
<interceptor-stack name="myInterceptionStack">
<!-- 加入默认的拦截器栈 -->
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="myInterception"></interceptor-ref>
</interceptor-stack>
</interceptors>
<!--用户 -->
<action name="user_*" class="ssh.org.web.UserAction" method="{1}">
<result name="success">/user/success.jsp</result>
<result name="input">/user/user.jsp</result>
<!-- 应用我自己的拦截器 -->
<interceptor-ref name="myInterceptionStack"/>
</action>
</package>
</struts>
----------------------------------------------------------------------
在struts2-core-2.1.2.jar 包中 , 根目录有一个struts-default.xml 定义默认拦截器: <default-interceptor-ref name="defaultStack"/>
内有大量的拦截器, 我们要扩展, 比如 :
<interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor"/>
<interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>
---------------------------------------------------------------------
附件中有 eclipse3.3 工程源码, 写的有点乱, 对付看吧.
分享到:
相关推荐
Struts2拦截器(Interceptor) Struts2拦截器(Interceptor)
Struts2拦截器.ppt Struts2拦截器.ppt Struts2拦截器.ppt
struts2,Interceptor struts2拦截器实例,两套实例,一套是针对单个的action配置的,另一套实例是针对全局的action配置的拦截器interceptor
Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序
关于struts2 拦截器的详细的解释及其在开发中对struts2的拦截器的应用和拦截器在框架中的作用.
Struts2拦截器实现权限控制demo,我感觉对初学者还是有一定帮助的
NULL 博文链接:https://cmexico.iteye.com/blog/621208
struts2拦截器应用小例子,与大家共分享
基于struts2的拦截器测试,实现了页面的跳转,中间过程的拦截
struts2拦截器的使用说明文档,配置说明文档。可以看一下
Struts2拦截器是在访问某个Action或Action的某个方法,字段之前或之后实施拦截,并且Struts2拦截器是可插拔的,拦截器是AOP的一种实现.
使用struts的拦截器拦截一些敏感性的词或一些非法或不文秘的言论
Struts2拦截器原理分析实例 博文链接:https://zmx.iteye.com/blog/457432
创建自己struts2拦截器,手工创建自己的拦截器实现
struts2拦截器和验证框架
struts2拦截器举例struts2拦截器举例struts2拦截器举例struts2拦截器举例
struts2拦截器和国际化教材源文件供大家学习
struts2常用拦截器,struts2经常用到的拦截器,熟悉熟悉
struts1.2拦截器使用插件