0

I have a form that contains various productID values. They are contained in an input text, with different values all having the same name.

<%
ListIterator ul2 = myCartList3.listIterator(); 
while(ul2.hasNext()){ 
    ShoppingCart myCart2 = new ShoppingCart();
    myCart2 = (ShoppingCart)ul2.next();
%>
<input type="text" value="<%=myCart2.getProductID() %>" name="productID"   size="3" />
<% 
} 
%>

When the form is submitted, it goes to the servlet. Usually I'd use request.getParameter but it only displays one attribute. How do I retrieve multiple attributes with the same name?

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
Azreen Putri
  • 1
  • 1
  • 1

2 Answers2

1

You can use

getParameterValues()

String[] productIDs= request.getParameterValues("productID");
Saif
  • 6,804
  • 8
  • 40
  • 61
0

The Javadoc for getParameter clearly says

You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use getParameterValues(java.lang.String).

And getParameterValues returns a String[], which is what you want.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110