This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Newbie: when to use form and request params Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Newbie: when to use form and request params" Watch "Newbie: when to use form and request params" New topic
Author

Newbie: when to use form and request params

Jehan Jaleel
Ranch Hand

Joined: Apr 30, 2002
Posts: 196
Hi all,
I have a newbie struts question. If I have a hidden field on my JSP and I want to pass the value in that field to my action, should I just use request.getParameter in my action as we would do in a servlet or should I make that hidden field a member variable of my form class and get it from there in the action?

I hope this is clear, please let me know if it is not.

Thanks.
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
I would use member variable in form class.


Amit Tank
Linked In
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Jehan,
I would also use a member variable in the form class. Keeping all the fields in one place (the form) makes it easier to see what the action uses. if some are using request.getParameter(), someone reading the code could get confused.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie: when to use form and request params
 
Similar Threads
question about hidden field and request paramter.
Can we send multiple textfield of same type in struts
struts link onclick question
request.setAttribute and getAttribute problem
text box displays when user select “Other” how to assign the value and retain the value when refresh