我自己实现拦截器接口,如:
public class MyInterceptor implements Interceptor{
public void destroy() {
System.out.println("销毁拦截器");

} public void init() {
System.out.println("初始化拦截器");

} public String intercept(ActionInvocation actionInvocation) throws Exception {
// TODO Auto-generated method stub
System.out.println("先执行拦截器");
String result = actionInvocation.invoke();
System.out.println("方法执行完了再次执行拦截器");
return result;
}
}下面是我的xwork.xml文件配置
<package name="" extends="webwork-default">
  <interceptors>
    <interceptor name="myinterceptor" class="cn.king.webwork.interceptor.MyInterceptor"/>
  </interceptors>
    <action name="first" class="first">
     <interceptor-ref name="myinterceptor"/>
     <interceptor-ref name="params"></interceptor-ref>
     <result name="success">success.jsp</result>
    </action>
  
  </package>
我的疑问是只要加了拦截器
如果不用这个拦截器
<interceptor-ref name="params"></interceptor-ref>
那我页面上的参数将不能够得到
这是为什么呢
望各位大侠指点
小弟谢过了

解决方案 »

  1.   

    因为他的参数是经过拦截器放到一个栈中。
    你自己<interceptor-ref name="myinterceptor"/> 加了这个拦截器后会把他默认加的覆盖掉.
    所有要显示加上他内置的
    <interceptor-ref name="params"> </interceptor-ref> 
    加上这个后还只是参数正常了。如果你还要用其他的话还得手动加。所以建议加上这个
    <interceptor-ref name="defaultStack" />
    这个是把他默认的拦截器都加上
      

  2.   

    你加了自定义的拦截器<interceptor-ref name="myinterceptor"/>就会把默认拦截器覆盖掉,所以还要显示的加入默认拦截器<interceptor-ref name="defaultStack" /> 默认拦截器实现了大部分xwork的功能,其中包含了这个拦截器<interceptor-ref name="params"> </interceptor-ref> 这个拦截器是用来拦截前台页面传过来的参数的