• 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

req.getParameterValues?

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP:
<% for (int i = 0; i < 5; i ++) {%>
<input type ="text" name="txtName" value = "<%=i%>"
<select name ="sAmount">
<option value="<%=i%>">....</option>
</select>
<%}%>
<input type="submit" name ="Submit" value="submit"/>

When click Submit buton, doPost called.
Servlet:
doPost() {
String Amount[] = req.getParameterValues("sAmount");
String Name[] = req.getParameterValues("txtname");
...
}

The length of Amount and Name are 5.
The value of Amount and Name usually are
Name [] = {0,1,2,3,4}
Amount[] = {0,1,2,3,4}
or value got random in range {0,1,2,3,4,}?

Please help.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Viet Jav,

What is your question?
 
Viet Jav
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Julian Kennedy,

I am sorry.
My question is what are values of Amount and Name in order?

JV.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think there is any guarantee that the order will be the same as on the form when you have multiple values with the same name.
Bill
 
Viet Jav
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William Brogden,

Suppose that order will be NOT the same as on the form when you have multiple values with the same name.
But order of Name's values and order of Amount's values are correlative?
ex:
If Order in Name is Name [] = {3,0,2,4,1}, order in Amount will also be Amount[] = {3,0,2,4,1}.

JV.
 
Sheriff
Posts: 67746
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
No such guarentees are made. If you need them to be in a specific order, or to correlate to each other, you'll need to come up with another scheme for naming the form elements.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Viet

Common solution for the above problem is while creating the jsp page create the textbox by using array
i.e name=txtName[i]

in the servlet you can retrieve by using the same order.it will be in the same order as your passing from the html page.

bye
vijay
 
Viet Jav
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vijaya,

Thank for your help.

Can you explain in detail?

In Servlet, What do I do to get in the same order?

JV.
[ September 01, 2004: Message edited by: Viet Jav ]
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should loop over the textName[i] to get the values.

For example, In your jsp you would be doing something like this.

<% for (int i = 0; i < 5; i++){ %>
<input type="text" name='<%="textName"+i%>' value=<%=i%>>
<%}%>

In your servlet you should get the values by doing something like this.

for (int i = 0; i < 5;i++){
val = request.getParameter(("textName"+i));
}

I guess I have interpreted what vijaya has suggest correctly.
I guess this should work
 
Viet Jav
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
I understanded.

JV.
reply
    Bookmark Topic Watch Topic
  • New Topic