Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to default action in Struts 2

I have an action with an empty string for name defined in the root namespace, and I want to redirect to that action from another action if a certain result is found, but it doesn't seem to work.

Here's the default action

<action name="" class="com.example.actions.HomeAction">
    <result name="success" type="freemarker">freemarker/home.ftl</result>
</action>

And I'm defining the redirect in the global-results for the package:

<global-results>
    <result name="sendToRouting" type="redirectAction">
        <param name="actionName"></param>
        <param name="namespace">/</param>
    </result>
</global-results>

I've tried taking out the actionName parameter, but that doesn't work. If I put a name in for the HomeAction and reference it by name in the global-results it works, so I'm assuming the problem is lack of action name for the redirect.

Any thoughts?

like image 531
topher-j Avatar asked Dec 10 '22 17:12

topher-j


1 Answers

I think that what you want to do is use <default-action-ref />:

<package name="home" namespace="/" extends="struts-default">
    <default-action-ref name="home" />

    <action name="home" class="com.example.actions.HomeAction">
        <result name="success" type="freemarker">freemarker/home.ftl</result>
    </action>

</package>

Sorry...misread the question:

Try changing type="redirectAction" to type="redirect", I'm fairly sure that redirectAction is now redirect.

like image 185
Thomas Avatar answered Mar 23 '23 07:03

Thomas