• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

pass values between pages using Struts2

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a register page with 2 fields and submit button. Once submitted I want to show a success page with paramaters entered in the prev page.

Very Simple but I am not clear how to do this with STRUTS2

ACTION CLASS --




JSP


Register.jsp


Sucess.jsp


I am getting message Thanks for registering: but not the value of the firstname. In old versions of struts
it would be setting a Request attribute and getting value from it on the JSP page. I am not sure how it is done in STRUTS2

appreciate reply.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please put your code inside code tags so it's legible.

Actions are instantiated per-request. If you don't save the user's name anywhere or pass it on to the next action there's no way for the next action to have that value. Not knowing how you've configured your result makes it harder to help.
 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to pass the firstname entered on the form to my success page.

In struts 2 examples. I haven't seen anyone using request.getParameter("firstname") to get form values or use request.setAttribute("fname",firstname) to pass values to another page.

can some one direct me on how to get form field values from my jsp page in STRUTS2?

 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

In struts 2 provide better facility than older version.

You can get variable using more than one style.

you can also use request for get it by just implement ServletRequestAware and Add unimplemented method.


Or you can directly use or define one String variable which name is match to your jsp page firstname tag like

<s:textfield cssClass="textfield" theme="simple" name="firsttName" />

then declare

private String firsttName;

and use getter and setter method for firsttName in Action you can directly get the value of firsttName.

so no need to take request object.

because Struts 2 place all the Action variable at OGNL value statck So, you can get it directly.


 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is a simple form field like this it is working fine.



but If I have a java bean I am unable to pass value to next page. I want to know how to pass complex objects? Appreciate your reply.


 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally I got it. Looks like there was a problem with names of the field and getter and setter names. I fixed the code on my first message too.
 
reply
    Bookmark Topic Watch Topic
  • New Topic