struts 拦截器 初始化参数问题

csdnduogui 2015-07-10 06:13:16
拦截器:
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class TestInterceptor implements Interceptor{
private String hello;
public void setHello(String hello) {
this.hello = hello;
}
public String intercept(ActionInvocation arg0) throws Exception {
System.out.print("hello:" + this.hello);
return arg0.invoke();
}
public void init() {
}
public void destroy() {
}
}

配置文件:
<interceptors>
<interceptor name="testInterceptor" class="com.xxx.interceptor.TestInterceptor">
<param name="hello">world</param>
</interceptor>
</interceptors>
<!-- 转向 -->
<action name="next" class="com.xxx.common.action.NextAction">
<!-- 定义逻辑视图和物理资源之间的映射 -->
<result name="success">${address}</result>
<interceptor-ref name="testInterceptor">
<param name="hello">world</param>
</interceptor-ref>
<interceptor-ref name="myDefaultStack"/>
</action>
怎么这个hello打死都传不过去呢,有什么没考虑到么?求大家指点。。
hello:null
...全文
136 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdnduogui 2015-07-12
  • 打赏
  • 举报
回复
引用 1 楼 panda_zhu 的回复:
你自定义的拦截器在配置文件里先声明一下,然后自定义一个拦截器栈,把你的拦截器和默认拦截器栈都加入进去,最后再讲容器默认拦截器栈改成你自定义的试一试。
struts 用的是2.1.8.1,而xwork版本低了,换成2.3.24后有新情况出现,我会开新帖说明,多谢。
panda_zhu 2015-07-11
  • 打赏
  • 举报
回复
你自定义的拦截器在配置文件里先声明一下,然后自定义一个拦截器栈,把你的拦截器和默认拦截器栈都加入进去,最后再讲容器默认拦截器栈改成你自定义的试一试。

81,092

社区成员

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

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