简体   繁体   中英

Struts2 prepare method

I'm working on a struts2 application and I have 4 actions related. When I call the first one "EditMagazineAction" y want sometimes to be redirected to "EditBooksAction".
I want this redirection when I'm coming from "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". 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. 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".

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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