struts2出现诡异异常

xsgydll 2011-08-27 02:33:33
自定义了一个拦截器,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>
...全文
43 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
老松鼠 2011-08-27
  • 打赏
  • 举报
回复
以前遇到过类似问题
楼主解决问题很速度嘛
xsgydll 2011-08-27
  • 打赏
  • 举报
回复
解决方式知道了
<interceptor-stack name="myStack">
<interceptor-ref name="myInterceptor"></interceptor-ref>
<interceptor-ref name="myInterceptor2"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref><!-- 必须放在最后 -->
</interceptor-stack>
xsgydll 2011-08-27
  • 打赏
  • 举报
回复
控制台没有打印出intercept,但是打印出action的validate方法里打印的内容

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧