1。struts2是原形的。Servlet是单例的

2。拦截器

1。自定义拦截器的话 首先要继承AbstractInterceptor接口 重写Interceptor方法


public class MyInterceptor extends AbstractInterceptor {


@Override

public String intercept(ActionInvocation arg0) throws Exception {

// TODO Auto-generated method stub

long one =System.currentTimeMillis();

String result=arg0.invoke();//调用Action

long two=System.currentTimeMillis();

System.out.println(".."+(two-one));

return result;

}

}

2.配置拦截器

<interceptors>

<interceptor name="myinterceptor" class="com.Interceptor.MyInterceptor"></interceptor>

</interceptors>

3.应用拦截器


<action name="inter" class="com.act.InterceptorAction" method="testInter">

<result>index.jsp</result>

<interceptor-ref name="myinterceptor"/>

<interceptor-ref name="defaultStack"/>

</action>

此外Struts还提供了20多个拦截器供调用