柚子快报激活码778899分享:struts2自己定义拦截器

http://yzkb.51969.com/

首先是struts2框架中基本的两个文件:一个是拦截器类,另外一个是struts.xml配置文件。

简单来说,一个是说明要做的事,一个是说明在哪里做的。

拦截器类

package com.test.interceptor;

import com.opensymphony.xwork2.ActionInvocation;

import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class TestInterceptor extends AbstractInterceptor{

/**

*

*/

private static final long serialVersionUID = 1L;

@Override

public String intercept(ActionInvocation invocation) throws Exception {

System.out.println("拦截器之前。。。。。。。。。。。");

String result=invocation.invoke();

System.out.println("。。。。。。。。。。拦截器之后。");

return result;

}

}

这个拦截器很easy,就是在全部动作之前和之后输出两段话。

struts.xml配置

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

/result.jsp

/login.jsp

输出结果

柚子快报激活码778899分享:struts2自己定义拦截器

http://yzkb.51969.com/

好文阅读

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。