"redirect"实现action的重定向:
<result name="error" type="redirect"> Register.action?username=${username} </result>
"redirectAction" 实现action的重定向:
<result name="error" type="redirectAction"> <param name="actionName">Register</param> <param name="username">${username}</param> </result>
或者:
<result name="error" type="redirectAction"> <param name="actionName"> Register?username=${username} </param> </result>
看了下"redirectAction"的实现类ServletActionRedirectResult.java,是这样描述的:
/**
* <!-- START SNIPPET: description -->
*
* This result uses the {@link ActionMapper} provided by the {@link ActionMapperFactory} to redirect the browser to a
* URL that invokes the specified action and (optional) namespace. This is better than the {@link ServletRedirectResult}
* because it does not require you to encode the URL patterns processed by the {@link ActionMapper} in to your struts.xml
* configuration files. This means you can change your URL patterns at any point and your application will still work.
* It is strongly recommended that if you are redirecting to another action, you use this result rather than the
* standard redirect result.
**/
它的意思是建议我使用这种方式来作action的重定向:
<result name="error" type="redirectAction"> <param name="actionName">Register</param> <param name="username">${username}</param> </result>
"This means you can change your URL patterns at any point and your application will still work."
显然这句话是Struts2强烈推荐使用的原因,但是不太能理解这句话。