• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

req.getParameterValues?

 
Viet Jav
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • 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.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viet Jav,

What is your question?
 
Viet Jav
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Julian Kennedy,

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

JV.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Vijaya Mohan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Saritha Penumudi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you.
I understanded.

JV.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic