问题
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.
回答1:
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.
回答2:
In struts.xml class you can specify
<result type="redirect"
name="failed">redirect action name</result>
In the action class you can use
return "falure"
or any of the constants existed in Action class
来源:https://stackoverflow.com/questions/15090217/actionredirect-migration-to-struts-2