如何使用参数重定向

时间:2014-06-12 06:09:46

标签: struts2 query-parameters post-redirect-get

<action name="AddedPaid"  class="iland.payment.SupplierPaidAction" method="insert">
  <result name="success"  type="redirect">ShowPaid</result>
  <result name="input">/pages/payment/addToPay.jsp</result>
  <result name="login">/pages/login.jsp</result> 
</action>   

<action name="ShowPaid" class="iland.payment.SupplierPaidAction" method="fetchAllByfk">
        <result name="success">/pages/paid/showPaidDetails.jsp</result>
        <result name="input">/pages/payment/ShowPay.jsp</result>
        <result name="login">/pages/login.jsp</result>            
 </action> 

此处AddedPaid Action用于将表单数据添加到数据库中。 将数据添加到数据库后,我将结果重定向到ShowPaid操作。 这工作正常。 我希望每当我将AddedPaid操作重定向到ShowPaid时。 ShowPaid必须显示我已在supplierPaymentId中添加数据的特定AddedPaid数据。

重定向后,它就是网址

http://localhost:8082/ClothStore/ShowPaid

我想要

http://localhost:8082/ClothStore/ShowPaid?supplierPaymentId=4

2 个答案:

答案 0 :(得分:2)

首先使用redirectAction结果代替redirect重定向到另一个操作。 并使用param标记在结果配置中添加参数。

<result type="redirectAction">
    <param name="actionName">ShowPaid</param>
    <param name="supplierPaymentId">${supplierPaymentId}</param>
</result>

请注意,您需要在动作类中使用supplierPaymentId的getter / setter。

答案 1 :(得分:2)

这很奇怪,通常人们有2并希望1:)

顺便说一句,既然你正在使用PostRedirectGet,你需要在Struts配置中手动传递参数。

假设你有一个带有getter和setter的名为supplierPaymentId的变量,它可以实现如下:

<action name="AddedPaid" class="iland.payment.SupplierPaidAction" method="insert">
    <result name="success"  type="redirectAction">
        <param name="actionName">ShowPaid</param>
        <param name="supplierPaymentId">${supplierPaymentId}</param>
    </result>  
    <result name="input">/pages/payment/addToPay.jsp</result>
    <result name="login">/pages/login.jsp</result> 
</action>   

还可以使用redirectAction而不是重定向,这意味着用于重定向到外部URL或非Action URL

相关问题