Java 谁调用Struts 2中拦截器的拦截方法
我正在使用Struts2拦截器,容器在咨询配置管理器(Java 谁调用Struts 2中拦截器的拦截方法,java,struts2,struts2-interceptors,Java,Struts2,Struts2 Interceptors,我正在使用Struts2拦截器,容器在咨询配置管理器(struts.xml)后为相关的操作类创建操作代理。现在是执行拦截器链的时候了,我有一个简单的问题-到底是谁在Myinterceptor类中调用了intercept方法 public class MyInterceptor implements Interceptor{ public void destroy() { // TODO Auto-generated method stub } pu
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调用的,与SpringAOP中的操作相同,proxyfactorybean也做了类似的事情来调用类的通知(切入点)
但我没有任何文件支持这一点。
请让我知道我是对的还是错的。您将其作为方法
截取的参数。您不必离开拦截器实例,因为调用方在拦截时会将自己传递给每个拦截器实例
调用此方法的位置是
默认的ActionInvocation实现
ActionInvocation类
框架首先调用ActionInvocation的invoke()方法来启动操作的执行
ActionInvocaton通过执行堆栈中的第一个拦截器来启动调用过程
您的拦截必须覆盖接口的方法intercept()
。只需将@Override
注释添加到您的方法中
@Override
public String intercept(ActionInvocation ai) throws Exception {
//your code
}
是的,但我想知道像‘myInteceptor.intercept(ai)’这样的语句是从哪里被调用的。嘿!如果你发现答案是正确的,那么请接受答案。它不能回答问题。而@Override
注释只是一个标记。创建拦截器后,在拦截器接口中调用init方法。然后init调用intercept。但要调用方法拦截器,必须重写。有关更多信息,请阅读以下文章:init
方法不调用intercept
方法。方法重写不是通过@Override
注释实现的(它只是一个标记)。
@Override
public String intercept(ActionInvocation ai) throws Exception {
//your code
}