不明白struts中Interceptor的调用过程(Interceptors的遍历过程),自己写了个小程序测试。得不到想要的结果 求大神指点啊~~ 代码如下:
public class Interceptor {
Invocation test;
String name;
public Interceptor(String name){
this.name=name;
}
public String intercept(Invocation test) {
this.test=test;
System.out.println("--name--1--"+name);
test.invoke();
System.out.println("--name--2--"+name);
eturn super.toString();
}
}
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Invocation {
public static void main(String[] args) {
Invocation t = new Invocation();
t.invoke();
}
public void invoke(){
List<Interceptor> list = new ArrayList<Interceptor>();
list.add(new Interceptor("aaaaa"));
list.add(new Interceptor("bbbbb"));
list.add(new Interceptor("ccccc"));
list.add(new Interceptor("ddddd"));
list.add(new Interceptor("eeeee"));
list.add(new Interceptor("fffff"));
list.add(new Interceptor("ggggg"));
list.add(new Interceptor("hhhhh"));
Iterator<Interceptor> iss = list.iterator();
if(iss.hasNext()){
Interceptor ms = iss.next();
ms.intercept(this);
}
}