struts拦截器使用
一 方法调用之后使用的拦截器 实现interceptor 接口
拦截器 一定是线程安全的就是要同步
public interface Interceptor extends Serializable
{
void destroy();
void init();
String intercept(ActionInvocation invocation) throws Exception;
}
实现方法intercept
example
import comopensymphonyxworkActionInvocation; import comopensymphonyxworkinterceptorAbstractInterceptor; public class SimpleInterceptor extends AbstractInterceptor
{
public String intercept(ActionInvocation invocation) throws Exception
{
MyAction action = (MyAction)invocationgetAction();
actionsetDate(new Date());
return invocationinvoke();
}
}
<struts>
<package name=strutsdefault>
<interceptors>
<interceptor name=alias class=comopensymphonyxworkinterceptorAliasInterceptor/>
<interceptor name=autowiring class=comopensymphonyxworkspringinterceptorActionAutowiringInterceptor/>
</interceptors>
</package>
</struts>
二 要实现在之前 调用 就实现 PreResultListener的接口