4

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.

Aung Thet
  • 3,051
  • 3
  • 13
  • 18

1 Answers1

4

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

Pratik Bhajankar
  • 1,144
  • 2
  • 14
  • 27
  • I have already getter and setter in UserAffair class. If I set fixed "id" like: 1,2,3 and directly trigger viewProfile action, the parameter "id" can be printed out in jsp page. – Aung Thet Feb 22 '16 at 00:31