Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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 如何在jsp中使用for循环来循环复选框?_Java_Jsp - Fatal编程技术网

Java 如何在jsp中使用for循环来循环复选框?

Java 如何在jsp中使用for循环来循环复选框?,java,jsp,Java,Jsp,我正在尝试使用for loop循环复选框。我写c:forEach来循环检查复选框。复选框根据数据库中的数据字段显示。但是当我尝试选中这些复选框时,只有一个复选框被选中。我做错了什么 复选框 <c:forEach items="${brandlist}" var="brand" begin="0" end="5" varStatus="loop"> <div class="custom-control custom-checkbox"> &l

我正在尝试使用for loop循环复选框。我写
c:forEach
来循环检查复选框。复选框根据数据库中的数据字段显示。但是当我尝试选中这些复选框时,只有一个复选框被选中。我做错了什么

复选框

<c:forEach items="${brandlist}" var="brand" begin="0" end="5"
    varStatus="loop">
    <div class="custom-control custom-checkbox">
        <input type="checkbox" class="custom-control-input" id="customCheck1"
            name="brand"> <label class="custom-control-label" for="customCheck1">${brand.brand}</label>
    </div>
</c:forEach>

${brand.brand}

为什么只选中一个复选框

添加后我的问题解决了

<c:forEach items="${brandlist}" var="brand" begin="0" end="5"
varStatus="loop">
<div class="custom-control custom-checkbox">
    <input type="checkbox" class="custom-control-input"
        id="${brand.brand}" name="${brand.brand}"> <label
        class="custom-control-label" for="${brand.brand}">${brand.brand}</label>
</div>

${brand.brand}

原因是每次迭代时,您的id都是相同的。这意味着<代码> ID=“CuthCuffs1将是整个列表。因此,这将被视为一个单一的选择。尝试在<代码> ID 和<代码>中添加索引,以便< /COD>属性,这样它就不同了。是的,我的问题解决了,我忘记了动态添加ID。