• Post Reply Bookmark Topic Watch Topic
  • New Topic

getParameter question  RSS feed

 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I woud not adopt Struts for something so trivial.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!