柚子快报激活码778899分享:struts2自己定义拦截器
首先是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">
输出结果
柚子快报激活码778899分享:struts2自己定义拦截器
好文阅读
发表评论