Java 如何识别用户选择了哪些?
我在jsp上有两个列表。第一个是productGroupName,第二个是products 现在,我展示这些,如下所示Java 如何识别用户选择了哪些?,java,javascript,jsp,servlets,struts,Java,Javascript,Jsp,Servlets,Struts,我在jsp上有两个列表。第一个是productGroupName,第二个是products 现在,我展示这些,如下所示 <html:form action="/priceOrder"> <table width="100%" id="tableStyle" style="font: message-box;padding: 20px;"> <logic:iterate id="productGroups" name="productGroup">
<html:form action="/priceOrder"> <table width="100%" id="tableStyle" style="font: message-box;padding: 20px;">
<logic:iterate id="productGroups" name="productGroup">
<tr>
<td>
<h3 style="background-color: #720D00; color: white;"><bean:write
name="productGroups" property="prodGroupName" /></h3>
<table width="100%" id="tableStyle" style="font: message-box; color: white; padding: 20px; background: #F15A00;">
<tr>
<td width="200px"><strong>Product Name</strong></td>
<td width="100px"><strong>How Many</strong></td>
<td><strong>Info</strong></td>
</tr>
<logic:iterate id="product" name="products">
<tr>
<c:if test="${(productGroups.prodGroupID) == (product.prodGroupID)}">
<td>
<html:checkbox property="productChecked" ><bean:write name="product" property="prodName"/></html:checkbox> <br />
</td>
<td><html:text property="quantity" styleId="check" size="5"/></td>
<td><bean:write name="product" property="prodDesc" /></td>
</c:if>
</tr>
</logic:iterate>
</table>
</td>
</tr>
</logic:iterate>
<tr align="center" style="background-color: #F15A00;"><td height="50px">
<html:submit styleId="buton" property="method"><bean:message key="button.order" /></html:submit>
</td></tr>
<tr><td></td></tr>
</table></html:form>
产品名称
有多少
信息
正如您首先看到的,我迭代了productGroupName,显示productID是否等于productGroupName下的productGroupID。但我在获取复选框和数量信息时遇到问题。我需要检查哪个产品以及需要多少产品。我不使用Struts,但他们的文档至少表明您需要进行此操作。与其直接提交表单,不如通过JS函数提交表单。在JS函数中,由于您正在迭代列表并为复选框和文本字段指定相同的名称,因此将得到一个同名数组。 也就是说,您将获得一个ID数组。您可以获取所选复选框的索引、数量、相应的列表元素,并使用该值填充单独的隐藏表单变量。然后提交 另一种方法是将一个隐藏变量与每个复选框关联,从而在列表和复选框之间提供一些映射