Darshika Sanghi Darshika Sanghi - 3 months ago 9x
Java Question

getting null values for textbox for selected checkbox in a row while sending from jsp to servlet

<c:forEach var="product" items="${list}">

<td align="center"><%-- <input type="hidden"
value="${product.productId}" name="id"> --%> <c:out
value="${product.productName}" /></td>
<td align="center"><c:out value="${product.productPrice}" /></td>
<td align="center"><input type="text" name="quantity<c:out value="${product.productId}" />"
value="<%=1%>" /></td>
<td align="center"><input type="checkbox" name="selectedItems"
value="<c:out value=" ${product.productId}"/>"/></td>

getting null value for quantity for particular selected row by checkbox in servlet


The problem is in line name="quantity<c:out value="${product.productId}" />". Try changing to name='quantity<c:out value="${product.productId}" />' if your intention is to have name, e.g. like name=quantity1, name=quantity2, etc.

Or alternatively set the value of the quantity as ${product.productId}, e.g.

<td align="center"><input type="text" name="quantity" value='<c:out value="${product.productId}" />' /></td>


Try to simplify your problem before jumping into the loop. Now are you able to process this as JSP POST form and see if you are able retrieve a value out of quantity?

    <td align="center"><input type="text" name="quantity" value="some default value before user overrides this" /></td>