读书人

struts2中应用自定拦截器

发布时间: 2012-08-21 13:00:21 作者: rapoo

struts2中使用自定拦截器

struts2中实现自定义的拦截器,有三种方式:

??? 1、实现interceptor接口

??? 2、继承AbstractInterceptor这个抽象类

??? 3、继承MethodFilterInteceptor类

?

这里我只用了第一种方式:

?

<interceptors > <interceptor name="InterceptorOne" name="code">import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class MyInterceptorOne implements Interceptor{ public void destroy() { // TODO Auto-generated method stub } public void init() { // TODO Auto-generated method stub } public String intercept(ActionInvocation invocation) throws Exception { // TODO Auto-generated method stub System.out.println("begin to intercept..."); String result = invocation.invoke(); System.out.println("end to intercept..."); return result; } } ?

?


?在配置文件中配置:

1 楼 lihengzkj 2011-10-25 编辑过程中出现了错误,谅解!拦截器的代码在最下面。

读书人网 >Web前端

热点推荐