xrcwrn
xrcwrn

Reputation: 5325

How to redirect with parameter

<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> 

Here AddedPaid Action is used to add form data in to database. After adding data in to database I am redirecting result to ShowPaid action. This is working properly. Now I want whenever I redirect AddedPaid action to ShowPaid. ShowPaid must show data of perticular supplierPaymentId for which I have added data in AddedPaid.

After redirect it is howing url

http://localhost:8082/ClothStore/ShowPaid

I want

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

Upvotes: 3

Views: 6675

Answers (2)

Andrea Ligios
Andrea Ligios

Reputation: 50203

It's strange, usually people have 2 and want 1 :)

Btw, since you are using PostRedirectGet, you need to manually pass the parameter in Struts configuration.

Assuming you have a variable named supplierPaymentId with getter and setter, it's achievable like follows:

<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>   

Also use redirectAction instead of redirect, that is meant to be used to redirect to external URLs or non-Action URLs

Upvotes: 6

Aleksandr M
Aleksandr M

Reputation: 24396

First of all use redirectAction result instead of redirect to redirect to another action. And use param tag to add parameters in your result configuration.

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

Note you need to have getter/setter for supplierPaymentId in your action class.

Upvotes: 2

Related Questions