如何使用参数重定向

xrc*_*wrn 2 struts2 post-redirect-get query-string

<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> 
Run Code Online (Sandbox Code Playgroud)

这里AddedPaidAction用于将表单数据添加到数据库中。将数据添加到数据库后,我将结果重定向到ShowPaid操作。这是正常工作的。现在我希望每当我将AddedPaid操作重定向到ShowPaid. 必须显示我已在 中添加数据ShowPaid的特定数据。supplierPaymentIdAddedPaid

重定向后是怎样的 url

http://localhost:8082/ClothStore/ShowPaid
Run Code Online (Sandbox Code Playgroud)

我想

http://localhost:8082/ClothStore/ShowPaid?supplierPaymentId=4
Run Code Online (Sandbox Code Playgroud)

And*_*ios 5

很奇怪,通常人们有 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>   
Run Code Online (Sandbox Code Playgroud)

还可以使用redirectAction代替redirect,即用于重定向到外部URL或非Action URL