Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何动态更改HTML输入名称_Java_Html_Jsp - Fatal编程技术网

Java 如何动态更改HTML输入名称

Java 如何动态更改HTML输入名称,java,html,jsp,Java,Html,Jsp,我正在创建一个小型购物车项目,在这个项目中,我从servlet中获得一个链接列表中的产品列表。现在,我在一个表中打印linkedlist的值,其中有一个选项供用户选择他们想要的数量。 选择的数量应作为属性转到下一页 以下是我面临的几个问题: 1:因为列表中有1个以上的项目,所以列出的每个项目都应该有 输入字段。如何动态更改 我以后可以用作属性的数量 2:商品的可用数量因产品而异,具体数量如何 我将数量的最大值设置为可用库存 3:如果我能设法获得这些值,我该如何设置所有属性。 它是在for循环内还

我正在创建一个小型购物车项目,在这个项目中,我从servlet中获得一个链接列表中的产品列表。现在,我在一个表中打印linkedlist的值,其中有一个选项供用户选择他们想要的数量。 选择的数量应作为属性转到下一页

以下是我面临的几个问题:

1:因为列表中有1个以上的项目,所以列出的每个项目都应该有 输入字段。如何动态更改 我以后可以用作属性的数量

2:商品的可用数量因产品而异,具体数量如何 我将数量的最大值设置为可用库存

3:如果我能设法获得这些值,我该如何设置所有属性。 它是在for循环内还是在for循环外

下面是代码供参考


在此处插入标题
欢迎来到购物世界
以以下身份登录:
项目清单
项目ID
名称
类别
价格
可用
量
试试这个:

<td><input type="number" name="quantity<%=i%>" min="0" max="<%=listp.get(i).getQuantity()%>"></td>


并且您需要设置循环外部的所有属性。像这样编辑代码

<%List<ItemDetailsPojo> listp = (List<ItemDetailsPojo>) session.getAttribute("ItemsData");

            %>
            <%-- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> --%>
            <Center>
                <h3 style="color: blue">Welcome To the World of Shopping</h3>
            </Center>
            <div align='right'>Logged in as:</div>

         <div align="center">
                <table border="10" cellpadding="5">
                    <caption>
                        <h2>List of Items</h2>
                    </caption>
                    <tr>
                        <th>ItemId</th>
                        <th>Name</th>
                        <th>Category</th>
                        <th>Price</th>
                        <th>Available</th>
                        <th>Quantity</th>
                    </tr>
                    <%
     String name;
    for(int i=0;i<listp.size();i++){%>
                        <tr>
                            <td><%out.println(listp.get(i).getItemId());%></td>
                            <td><%out.println(listp.get(i).getItemName());%></td>
                            <td><%out.println(listp.get(i).getCategory());%></td>
                            <td><%out.println(listp.get(i).getPrice());%></td>
                            <td><%out.println(listp.get(i).getQuantity());%></td>
                            <% int number = listp.get(i).getQuantity();
    name="quantity".concat(listp.get(i).getQuantity());
     %>
                            <td><input type="number"name="<%=name%>" min="0" max="should change according the the quantity  available"></td>
                        </tr>
                    <%} %>
                </table>

            </div>


    </body>
    </html>

欢迎来到购物世界
以以下身份登录:
项目清单
项目ID
名称
类别
价格
可用
量

非常有魅力,谢谢
<%List<ItemDetailsPojo> listp = (List<ItemDetailsPojo>) session.getAttribute("ItemsData");

            %>
            <%-- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> --%>
            <Center>
                <h3 style="color: blue">Welcome To the World of Shopping</h3>
            </Center>
            <div align='right'>Logged in as:</div>

         <div align="center">
                <table border="10" cellpadding="5">
                    <caption>
                        <h2>List of Items</h2>
                    </caption>
                    <tr>
                        <th>ItemId</th>
                        <th>Name</th>
                        <th>Category</th>
                        <th>Price</th>
                        <th>Available</th>
                        <th>Quantity</th>
                    </tr>
                    <%
     String name;
    for(int i=0;i<listp.size();i++){%>
                        <tr>
                            <td><%out.println(listp.get(i).getItemId());%></td>
                            <td><%out.println(listp.get(i).getItemName());%></td>
                            <td><%out.println(listp.get(i).getCategory());%></td>
                            <td><%out.println(listp.get(i).getPrice());%></td>
                            <td><%out.println(listp.get(i).getQuantity());%></td>
                            <% int number = listp.get(i).getQuantity();
    name="quantity".concat(listp.get(i).getQuantity());
     %>
                            <td><input type="number"name="<%=name%>" min="0" max="should change according the the quantity  available"></td>
                        </tr>
                    <%} %>
                </table>

            </div>


    </body>
    </html>