webwork2拦截器问题

jumpheightway 2009-08-01 08:30:12
我自己实现拦截器接口,如:
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>
那我页面上的参数将不能够得到
这是为什么呢
望各位大侠指点
小弟谢过了
...全文
139 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
musecangying007 2009-08-05
  • 打赏
  • 举报
回复
你加了自定义的拦截器<interceptor-ref name="myinterceptor"/>就会把默认拦截器覆盖掉,所以还要显示的加入默认拦截器<interceptor-ref name="defaultStack" /> 默认拦截器实现了大部分xwork的功能,其中包含了这个拦截器<interceptor-ref name="params"> </interceptor-ref> 这个拦截器是用来拦截前台页面传过来的参数的
sahala3293 2009-08-05
  • 打赏
  • 举报
回复
因为他的参数是经过拦截器放到一个栈中。
你自己<interceptor-ref name="myinterceptor"/> 加了这个拦截器后会把他默认加的覆盖掉.
所有要显示加上他内置的
<interceptor-ref name="params"> </interceptor-ref>
加上这个后还只是参数正常了。如果你还要用其他的话还得手动加。所以建议加上这个
<interceptor-ref name="defaultStack" />
这个是把他默认的拦截器都加上

81,091

社区成员

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

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