This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes request.getParameter access the Struts form values    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "request.getParameter access the Struts form values    " Watch "request.getParameter access the Struts form values    " New topic
Author

request.getParameter access the Struts form values

satish jupalli
Greenhorn

Joined: Apr 06, 2003
Posts: 10
Is it OK to access struts form bean properties using the
[code]
request.getParameter
[code]
I expected it to return "null" if we do so. However it is returning the values. Can somebody please clarify this.

Regards
Satish
satish jupalli
Greenhorn

Joined: Apr 06, 2003
Posts: 10
To give more clarity I'm also posting what I was doing.

<form name="SearchForm" method="POST" action="/Search.do?
<input type="hidden" name="Search" value=""/>
<input type="text" name="param1" value=""/>
<input type="text" name="param2" value=""/>
<button name="submit" type="submit" >
</form>

Once I submit the form. In the action class , i have the following code

[code]
System.out.print( request.getParameter("param1") );
System.out.print( request.getParameter("param2") );
[code]

Wether it should return the values what ever I have enter while posting the form or not. I thought it will return null. Please correct me if Im wrong.

Thanks!!
Manuel Jordan
Ranch Hand

Joined: Sep 29, 2006
Posts: 131
Hello

mmm, yes works, but you must use an ActionForm or ValidatorForm (based in Pojo), your way no use an ActionForm or pjo variables where is the <html:form> ???

is easier than use the classic request way, and think about validation and messages, is very related with the Form

i no saw any tag (bean and html) in your example, very long time ago that i didnt use request to assign values

regards


kill your pride, share your knowledge with all
satish jupalli
Greenhorn

Joined: Apr 06, 2003
Posts: 10
Even if I Use <html:form> and post method for sumiting the form, is it OK
to use request.getParameter() to get the one of the fields of the form.
Howerver, when I see the ParameterMap of the request Object it has Zero size.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I guess I am not sure what you are asking. Your jsp file will render a standard html page containing a form tag and input tags. When the user submits this page, standard html behavior is to submit these values on the request. Struts adds a layer on top that instantiates your form and populates the properties based on values from the request, but Struts does not remove these values from the request. If you want to access the request directly you can, but it is generally a lot easier to just access the properties from your form.

- Brent
Manuel Jordan
Ranch Hand

Joined: Sep 29, 2006
Posts: 131
Hello

the post by Brent is fairly correct, pojo is your friend and struts work with pojo for your Form's

simple and easy

regards
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: request.getParameter access the Struts form values
 
Similar Threads
Null values, post forms....?!
how to get multple text fields values in jsp
enctype="multipart/form-data" request.getParameter() issue
Inserting constant values but not form values on html form on web using tomcat
Another simple question