Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect struts action with dynamic parameter

I want to redirect action with parameter "id".

I used this code in struts.xml

<action name="register" class="com.framework.strust2.UserAffair">
        <result name="success" type="redirectAction">
            <param name="actionName">viewProfile</param>
            <param name="id">${id}</param>
        </result>
</action>

It works for action redirecting and parameter name id, but not parameter value ${id}. It only works with constant id, like;

 <param name="id">1</param>

Though I searched the solution of my problem, there is nothing case that matches what I needed. Pls.

like image 265
Aung Thet Avatar asked Oct 22 '25 18:10

Aung Thet


1 Answers

For passing the parameter with action you should have to define that variable in action and if you are using model driven approach then that parameter should be in pojo i.e

it is your struts.xml action configuration.

<action name="register" class="com.framework.strust2.UserAffair">
    <result name="success" type="redirectAction">
        <param name="actionName">viewProfile</param>
        <param name="id">${id}</param>
    </result>
</action>

so in you action class there should be variable sayaing id. i.e

class UserAffair{
 private int id;

 //setter and getter
}

and if you are using model drivan then in your pojo there should be a variable saying id.

hope so this will help you a lot

like image 173
Pratik Bhajankar Avatar answered Oct 25 '25 21:10

Pratik Bhajankar



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!