关于Struts2的action重定向

"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强烈推荐使用的原因,但是不太能理解这句话。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值