• 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

request.getParameter access the Struts form values

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
satish jupalli
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic