Search code examples
javastruts2migrationstrutsactionresult

ActionRedirect migration to Struts 2


I'm currently migrating a wepapp from Struts to Struts 2 and I'm experiencing some difficulties.

I have some ActionRedirect with no extra parameters given to it and I don't know how to migrate it, maybe just return a string is efficient?

For example I have this :

return new ActionRedirect(mapping.getFindforward("failed");

Is it efficient to do that instead ?

return "failed";

And when I have parameters how can i migrate it ? I'm working on that part since 2 days.


Solution

  • In Struts2 redirects are made if you create the result of type "redirect" if you want to redirect to a specific URL, or "redirectAction" if you want to redirect to the known action in the configuration.

    These results you may configure on action or globally like forwards in the Struts1.

    The difference is that you don't need to find it in the mapping it will be done by the framework.

    If you return "failed" the framework will look up the configuration for the result named "failed" and if it fails finding such result it will throw an exception.