繁体   English   中英

Struts 2.3 Store Interceptor:如何将ActionErrors从Interceptor传递给Action?

[英]Struts 2.3 Store Interceptor : How to pass ActionErrors from Interceptor to Action?

我一直在 Struts 2 文档中阅读有关StoreInterceptor的内容,它讨论了如何将 StoreInterceptor 粘贴到您的struts-config.xml中的 Action 定义中,并且它可以正常工作。 但那是如果您从 Action 中创建和添加ActionErrors

我的问题是我正在使用LoginInterceptor进行登录,如果登录失败,则会添加一个ActionError如下所示:

((ActionSupport) invocation.getAction()).addActionError("Login failed");

它添加得很好,但是当我到达在 LoginInterceptor之后调用的LoginInterceptorValidationAwareSupport.actionErrorsnull

我认为通过像这样添加StoreInterceptor ,它会在请求或会话中存储ActionErrors (使用operationMode "store""retreive"参数):

<action name="login" class="...LoginFormAction" >
 <interceptor-ref name="store">
  <param name="operationMode">store</param>
 </interceptor-ref>
 <interceptor-ref name="defaultStack" />
  <result name="input" type="tiles">adminLogin</result>
  <result name="success" type="tiles">adminLogin</result>
</action>

但它不起作用。 我还尝试将StoreInterceptor直接添加到 defaultStack,这也不起作用。

StoreInterceptor是否不仅用于保存 Actions 之间的ActionErrors ,还用于保存 Interceptor 和 Actions 之间的ActionErrors

store拦截器在两个操作之间工作,其中一个存储消息,另一个检索消息。

在您的配置中,您只有一项操作。 第二个操作应配置为检索消息。

store拦截器在动作和拦截器之间或拦截器之间不起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM