一,<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);
}
}