Hoan Dang
Hoan Dang

Reputation: 2280

How to submit multiple value in asp form

In the PHP when I click submit the server will get all the submit value via $_POST

So how can I do same like that with asp

<form name="submitForm" method="post" action="cart?action=update">
    <c:forEach var="product" items="${products}">
        <input type="text" name="${product.productID}" value="${product.quantity}" />
    </c:forEach>
    <input type="submit" value="Update" />
</form>

I want after submitting, I can get only one value in the servlet and the value consists multiple input value without give it a particular name.

I tried

System.out.println(request.getParameterValues("submitForm"));

But its null

Could anyone point me out ? Thanks

Upvotes: 0

Views: 225

Answers (2)

Yogendra Singh
Yogendra Singh

Reputation: 34367

I believe, ${product.productID} is having different value in each record. Use the values from here to get the values in the server side. e.g. if ${product.productID} results into productId1, productId2, prductId3...., retireve the values as:

      request.getParameter("productId1");
      request.getParameter("productId2");
      request.getParameter("productId3");
      ......

If you are unsure about the names to retrieve, you may get them all parameter names using request.getParameterNames(). e.g. below:

    Enumeration<String> parEnumeration = request.getParameterNames();
    while (parEnumeration.hasMoreElements()) {
        String parameterName = parEnumeration.nextElement();
        String parameterValue = request.getParameter(parameterName);
        System.out.println("Parameter Name= " + parameterName);
        System.out.println("Parameter Value= " + parameterValue);
    }

Hope this helps.

Upvotes: 1

Pradeep Pati
Pradeep Pati

Reputation: 5919

submitForm is the form name and not the field identifier. Hence, trying to get parameter values for a field named submitForm will return null.

You should ideally change the name of the text field from ${product.productId} to something definite, such as "MyProducts", and then do the call on that.

Upvotes: 0

Related Questions