我可以在不同的动作类之间传播 struts2 ActionErrors 吗? [英] Can I propagate struts2 ActionErrors between different action classes?

查看:30
本文介绍了我可以在不同的动作类之间传播 struts2 ActionErrors 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个操作,结果是重定向操作到不同类中的另一个操作,是否有可能在结果操作中显示验证错误?例如.在下面的示例中,如果用户执行 actionA(没有与之关联的视图),并且出现错误,有没有办法在 actionB 结果 (foo.jsp) 中显示这些错误?还是我以完全错误的方式处理这个问题?

If I have an action where the result is a redirectAction to another action in a different class, is it possible to get validation errors to display in the resulting action? E.g. in the following example, if a user executes actionA (which has no views associated with it), and there are errors, is there any way to display those errors in the actionB result (foo.jsp)? Or am I going about this in completely the wrong way?

<package name="a" extends="struts-default" namespace="/a">
    <action name="actionA" class="actionAClass">
        <result name="input" type="redirectAction">
            <param name="actionName">actionB</param>
            <param name="namespace">/b</param>
        </result>
        <result type="redirectAction">
            <param name="actionName">actionB</param>
            <param name="namespace">/b</param>
        </result>
    </action>
</package>
<package name="b" extends="struts-default" namespace="/b">
    <action name="actionB" class="actionBClass">
        <result>/foo.jsp</result>
    </action>
</package>

推荐答案

可能有办法做到这一点,但我不认为这是使用 struts 的好方法.如果 actionA 验证失败,您很可能希望为它提供一个显示错误的非重定向输入结果,或者一个可以显示它的全局错误页面.

There may be a way to do that, but I don't think it's a very good way to use struts. If actionA is failing validation, you most likely would want to either have a non-redirect input result for it that shows the errors, or perhaps a global error page that can show it.

我想您可以将操作错误存储在重定向之间的会话之类的地方,但您不会真正使用框架的设计方式.

I suppose you could store the action errors somewhere like the session in between the redirect, but you wouldn't really be using the framework how it was designed.

这篇关于我可以在不同的动作类之间传播 struts2 ActionErrors 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆