我正在使用Struts2拦截器,容器在咨询配置管理器(struts.xml)后为相关的操作类创建操作代理。现在是执行拦截器链的时候了,我有一个简单的问题--到底是谁调用了Myinterceptor类中的intercept方法。
public class MyInterceptor implements Interceptor{
public void destroy() {
// TODO Auto-generated method stub
}
public void init() {
// TODO Auto-generated method stub
}
public String intercept(ActionInvocation ai) throws Exception {
// TODO Auto-generated method stub
long t1=System.currentTimeMillis();
ValueStack s= ai.getStack();
String val=s.findString("name");
s.set("name", val.toUpperCase()+"_changed");
return ai.invoke();
}
}根据我的理解,它是由相应action类的actionproxy调用的,在spring AOP中也是这样做的,在spring AOP中,proxyfactorybean会做类似的事情来调用类的advices (Pointcut)。
但我没有任何文档来支持这一点。请告诉我我是对的还是错的。
发布于 2015-03-08 05:47:11
您将其作为方法intercept的参数获取。您不必远离拦截器实例,因为调用者在拦截时会将自身传递给每个拦截器实例。
调用此方法的位置是DefaultActionInvocation
公共类DefaultActionInvocation扩展了对象实现ActionInvocation
默认的ActionInvocation实现
发布于 2015-03-09 18:12:25
ActionInvocation类
开始执行Action.
发布于 2015-06-11 19:27:23
您的截取必须重写接口Interceptor的方法intercept()。只需在方法中添加@Override注释即可。
@Override
public String intercept(ActionInvocation ai) throws Exception {
//your code
}https://stackoverflow.com/questions/28920086
复制相似问题