简体   繁体   中英

Why can't i redirect an action to another action in Struts2?

i am using Struts2. I have a dialog box with a list of persons that is update through the "search_users" action. Next to this list i have a form that you can use to add another person by calling the "add_user" action when the form is submitted.

What i'm trying to do is that, once the add_user action is performed, the list gets updated using the "search_user" action.

I tried using the result type "redirect" in the struts.xml like this:

<action name="search_users" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLSubequipo" method="searchUsers">
            <result name="success">list.jsp</result>
        </action>

        <action name="add_user" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLTipoEntregable" method="addUser">
            <result name="success" type="redirectAction">search_users</result>
        </action>

But that doesn't work. What am i doing wrong? Is there something i should add to the struts.xml file that i'm not aware of?

This is the error mesage i get:

"Caused by: There is no result type defined for type 'redirect-action' mapped with name 'success'.  Did you mean 'redirectAction'? - result - file:/.../struts.xml:59:44
    at ..."

Current Configuration:

<action name="add_user" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLTipoEntregable" method="addUser">
   <result name="success" type="redirectAction">search_users</result>
</action>

As per the documentation correct format is:

<action name="add_user" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLTipoEntregable" method="addUser">
    <result type="redirectAction">
        <param name="actionName">search_users</param>
        <!--<param name="namespace">/secure</param> This is optional if your action where you are redirecting is in the same namespace you can leave this, if your action is in some other name space then provide the namespace--> 
    </result>
</action>

Currently using Struts 2.3.20 , this works:

<result type="redirectAction">myAction</result>

I have not confirmed in prior versions.

I'm not a big Struts guy but based on the documentation it looks like your redirect is not syntactically correct: http://struts.apache.org/2.1.6/docs/redirect-action-result.html

<package name="public" extends="struts-default">
    <action name="login" class="...">
        <!-- Redirect to another namespace -->
        <result type="redirect-action">
            <param name="actionName">dashboard</param>
            <param name="namespace">/secure</param>
        </result>
    </action>
</package>

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