自定义了一个拦截器,init方法被执行了,但是intercept方法没有被执行
下面是自定义拦截器的代码
package com.test.interceptor;import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;public class MyInterceptor implements Interceptor { private String hello;

public String getHello() {
return hello;
} public void setHello(String hello) {
this.hello = hello;
} public void destroy() {
System.out.println("destroy"); } public void init() {
System.out.println(hello);
System.out.println("init"); } public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("intercept");
String result = invocation.invoke();
return result;
}}下面是struts.xml的代码:
<interceptors>
<interceptor name="myInterceptor" class="com.test.interceptor.MyInterceptor">
<param name="hello">world</param>
</interceptor>

<interceptor-stack name="myStack">
<interceptor-ref name="defaultStack"></interceptor-ref>

<interceptor-ref name="myInterceptor"></interceptor-ref>
</interceptor-stack>

</interceptors>
<default-interceptor-ref name="myStack"></default-interceptor-ref>

解决方案 »

  1.   

    控制台没有打印出intercept,但是打印出action的validate方法里打印的内容
      

  2.   

    解决方式知道了
    <interceptor-stack name="myStack">
    <interceptor-ref name="myInterceptor"></interceptor-ref>
    <interceptor-ref name="myInterceptor2"></interceptor-ref>
    <interceptor-ref name="defaultStack"></interceptor-ref><!-- 必须放在最后 -->
    </interceptor-stack>