如果我有一个动作,其中结果是一个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吗?
发布评论