• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

getParameter question

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have 2 jsps, where
jsp1 has a form and submits a dynamic number of textboxes and combo boxes
and
jsp2 which receives those submitted

now, in jsp1, my textbox names are arrays, as in:



and how do i get those values in my jsp2?
i need to retrieve all the values inputted in the dynamic number of textboxes i have

thanks
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i solved some of the problem:
i tried it with textboxes but it still doesn't work with combo boxes

this is what i did



and in jsp2


but if i do the same thing with combo boxes, it doesn't work

<select name="combo1">
<option value="1">1</option>
<option value="2">2</option>
</select>

and same as in jsp2
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your fields are named field0, field1, field2, field3..., then you have to retrieve the parameters under the names field1, field2, field3

ie


This code doesn't need to know how many items there are. It assumes when it doesn't find an item, that there are no more. That works for textboxes/select items, but won't work for checkboxes.


On request.getParameterValues(): this gets all the values for parameter.
eg reading=Headfirst Java&reading=Struts in Action&reading=Design Patterns
All of these have the same parameter name, but multiple values were submitted. However there is no guaruntee on the order of those parameters. In your case if the textbox and select box are linked, you can't be sure that you match them up correctly unless you number them yourself.

Also there is a useful package in the jakarta commons: BeanUtils.
If you name your fields field[0], field[1], field[2] then it will automagically retrieve them as array fields. (This is used in Struts)

Hope some of this helps,
evnafets
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks very much.

you're a very good teacher.
i'll try your code.
i'm just not too sure about the struts thing though. i don't know how it works and how to use it

thanks again
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I woud not adopt Struts for something so trivial.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic