struts2 的各种intercepter 介绍

一,<interceptor name="chain" class="com.opensymphony.xwork2.interceptor.ChainingInterceptor"/>

就是把这个action的result 转给下个action,那么这个action当中的 valueStack 需要拷贝到下个Action中去

 

 

 
 <action name="someAction" class="com.examples.SomeAction">
     <interceptor-ref name="basicStack"/>
     <result name="success" type="chain">otherAction</result>
 </action>
 
 <action name="otherAction" class="com.examples.OtherAction">
     <interceptor-ref name="chain"/>
     <interceptor-ref name="basicStack"/>
     <result name="success">good_result.ftl</result>
 </action>
 

 

其中可以配置的有struts2的3个常量:

 

  • struts.xwork.chaining.copyErrors - set to true to copy Action Errors(默认false)
  • struts.xwork.chaining.copyFieldErrors - set to true to copy Field Errors (默认false)
  • struts.xwork.chaining.copyMessages - set to true to copy Action Messages (默认false)
另外还有2个参数
 protected Collection<String> excludes;

 protected Collection<String> includes;
 这2个参数,如果excludes 被设置了,那么里面提到的参数将不被复制
 如果includes 被设置了,那么里面提到的参数将被复制
 如果includes 没有被设置,那么除了excludes 以外的都将被复制,详情可参见OgnlUtil.java当中的代码片段
 if (exclusions != null && exclusions.contains(fromPd.getName())) {
                    copy = false;
                } else if (inclusions != null && !inclusions.contains(fromPd.getName())) {
                    copy = false;
                }
 

========================================================

 

二,<interceptor name="cookie" class="org.apache.struts2.interceptor.CookieInterceptor"/>

主要用于将cookie中指定的name 和指定的 value ,放到valueStack中去

如果Action实现了CookieAware接口也可以参考如下代码

 /**
     * Hook that set the <code>cookiesMap</code> into action that implements
     * {@link CookiesAware}.
     *
     * @param action
     * @param cookiesMap
     */
    protected void injectIntoCookiesAwareAction(Object action, Map<String, String> cookiesMap) {
        if (action instanceof CookiesAware) {
            if (LOG.isDebugEnabled())
                LOG.debug("action ["+action+"] implements CookiesAware, injecting cookies map ["+cookiesMap+"]");
            ((CookiesAware)action).setCookiesMap(cookiesMap);
        }
    }
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值