[英]Struts2 prepare method
I'm working on a struts2 application and I have 4 actions related. 我正在开发一个struts2应用程序,我有4个相关的动作。 When I call the first one "EditMagazineAction" y want sometimes to be redirected to "EditBooksAction". 当我调用第一个“ EditMagazineAction”时,有时希望重定向到“ EditBooksAction”。
I want this redirection when I'm coming from "ValidateBooksAction". 当我来自“ ValidateBooksAction”时,我想要这种重定向。 So, I saved in session the value of what I'm coming from, and I call in EditMagazineAction's prepare a method that will check if I want to stay in this action, or change to "EditBooksAction". 因此,我在会话中保存了我所来自的值,然后在EditMagazineAction的prepare方法中进行调用,该方法将检查我是否要保留此操作,或者更改为“ EditBooksAction”。 If all I want to do is redirect to this one ("EditBooksAction"), I don't execute anything else on the prepare method of "EditMagazineAction", but if I wanna stay, I keep going on the prepare. 如果我只想重定向到该目录(“ EditBooksAction”),则不会对“ EditMagazineAction”的prepare方法执行任何其他操作,但是如果我想留下,我会继续进行准备。 This is working for me, but I was told that is not "really correct". 这对我有用,但有人告诉我这不是“正确的”。 How bad is this? 这有多糟? In this project I can't get a real redirection, I can't go directly to "EditBooksAction", so I must go via "EditMagazineAction". 在此项目中,我无法获得真正的重定向,无法直接进入“ EditBooksAction”,因此必须通过“ EditMagazineAction”。
You can use redirect action result like below 您可以使用如下所示的重定向操作结果
<package name="public" extends="struts-default">
<action name="action1" class="...">
<result name="redirect1" type="redirectAction">
<param name="actionName">action2</param>
</result>
<result name="no_redirect">my.jsp</result>
<result name="redirect2" type="redirectAction">
<param name="actionName">action3</param>
</result>
</action>
</package>
then in your action return redirect1
, no_redirect
or redirect2
. 然后在您的操作中返回redirect1
, no_redirect
或redirect2
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.