java - Printing an ArrayList in HTML and matching each item with an input box -


i'm working on piece of code have arraylist of items. i'm putting on webpage using html, , want print items in list input field next each item, user can type in quantity - kind of shopping cart.

how go doing purely in html document? doing within java code itself, understand bad practice, , don't know how retrieve number type in - how that?

would better off doing jsp? if so, can give me advice how go doing that?

thanks in advance. here code have been working far.

int counter = 1; out.println("<html><body><br><br>"); (gear g : gear) {     out.println(counter + ". " + g.tostring() + "&nbsp; &nbsp; &nbsp; &nbsp; <input type=\"text\" name=\"" + counter + "\">" + "<br>");     counter++; } out.println("<br><br><br> <input type=\"submit\" value=\"enter\" name=\"en\" </html></body>"); 

i've been using servlets , tomcat, way.

edit: see has said duplicate of previous question. argue question different, since focus here on html , not jsp - whatever, fine. if has thoughts on html here, appreciate them.

edit 2: alternatively, how might dynamically name each input box in loop?

<table>     <c:foreach items="${gear}" var="g">         <tr>             <td>${g.category}</td>              <td>${g.desc1}</td>             <td>${g.quant}</td>             <td><input type="text"></td>         </tr>     </c:foreach> </table> 

alternatively, how might dynamically name each input box in loop?

pfb answer

add varstatus in foreach , name input box below varstatus="vstatus" , input type="text" id="${pstatus}"

<table>     <c:foreach items="${gear}" var="g" varstatus="vstatus">         <tr>             <td>${g.category}</td>              <td>${g.desc1}</td>             <td>${g.quant}</td>             <td><input type="text" id="${pstatus}" name="${pstatus}"></td>         </tr>     </c:foreach> </table> 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -