Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 783
xrcwrn Avatar asked Mar 26 '26 14:03

xrcwrn


2 Answers

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

like image 171
Andrea Ligios Avatar answered Mar 30 '26 11:03

Andrea Ligios


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.

like image 30
Aleksandr M Avatar answered Mar 30 '26 12:03

Aleksandr M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!