可以在不同的动作类之间传播struts2 ActionErrors吗?

编程入门 行业动态 更新时间:2024-10-24 11:11:43
本文介绍了可以在不同的动作类之间传播struts2 ActionErrors吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我有一个动作,其中结果是一个redirectAction到另一个类中的另一个操作,是否可以获得验证错误以显示在生成的操作中?例如。在以下示例中,如果用户执行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吗?

本文发布于:2023-10-10 22:38:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479951.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动作类   ActionErrors

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!