Java 将选中的复选框值传递到Struts2中的数据库
我正在使用Struts2,这是我在JSP中的表单Java 将选中的复选框值传递到Struts2中的数据库,java,jsp,struts2,jstl,Java,Jsp,Struts2,Jstl,我正在使用Struts2,这是我在JSP中的表单 <s:form target="_top" cssClass="table-controls form-wrapper" name="incentives" id="frmIncentives" action="saveIncentives.action" method="post"> <div id="actionErrors" style="color: red;">
<s:form target="_top" cssClass="table-controls form-wrapper" name="incentives" id="frmIncentives" action="saveIncentives.action" method="post">
<div id="actionErrors" style="color: red;">
<s:actionerror />
<s:fielderror />
</div>
<table id ="showIncentives" cellspacing="0" cellpadding="0" border="1" width="500" >
<tr style="font-weight: bold">
<td><s:checkbox name="Select All" id="select_all"
theme="simple" /></td>
<td>
<td></td>
<td></td>
<td><s:text name="Marketing Incentive" /></td>
<td></td>
<td><s:text name="Advertising Incentive" /></td>
<td></td>
<td><s:text name="Channel Placement Incentive" /></td>
<td></td>
</tr>
<s:iterator value="incentiveList" status="stat">
<tr>
<td><s:checkbox name="checkboxes[%{#stat.index}]" theme="simple" /></td>
<td></td>
<td><s:property value="pricingTierId" /> <s:hidden value="%{incentiveList.pricingTierId}" /></td>
<td><s:property value="marketingAmount" /> <s:hidden value="%{incentiveList.marketingAmount}" /></td>
<td></td>
<td><s:property value="marketingIncentive" /></td>
<td></td>
<td><s:property value="advertizingIncentive" /></td>
<td></td>
<td><s:property value="channelPlacementIncentive" /></td>
<td></td>
</tr>
</s:iterator>
</table>
<c:if test="${fn:length(incentiveList) == 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="true"/>
</c:if>
<c:if test="${fn:length(incentiveList) gt 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="false"/>
</c:if>
</s:form>
<s:iterator value="incentiveList" status="stat">
<tr>
<td><s:checkbox name="checkboxes[%{#stat.index}]" theme="simple" /></td>
<td></td>
<td><s:property value="pricingTierId" /> <s:hidden name="pricingTierId" value="%{incentiveList.pricingTierId}" /></td>
<td><s:property value="marketingAmount" /> <s:hidden name="marketingAmount" value="%{incentiveList.marketingAmount}" /></td>
<td></td>
<td><s:property value="marketingIncentive" />
<s:hidden name="marketingIncentive" value="%{incentiveList.pricingTierId}" />
</td>
<td></td>
<td><s:property value="advertizingIncentive"/>
<s:hidden name="advertizingIncentive" value="%{incentiveList.pricingTierId}"/>
</td>
<td><s:property value="channelPlacementIncentive" />
<s:hidden name="channelPlacementIncentive" value="%{incentiveList.pricingTierId}" />
</td>
<td></td>
</tr>
</s:iterator>
仍然所有的值都被传递为null。
请建议您的表格如下所示
<s:form target="_top" cssClass="table-controls form-wrapper" name="incentives" id="frmIncentives" action="saveIncentives.action" method="post">
<div id="actionErrors" style="color: red;">
<s:actionerror />
<s:fielderror />
</div>
<table id ="showIncentives" cellspacing="0" cellpadding="0" border="1" width="500" >
<tr style="font-weight: bold">
<td><s:checkbox name="Select All" id="select_all"
theme="simple" /></td>
<td>
<td></td>
<td></td>
<td><s:text name="Marketing Incentive" /></td>
<td></td>
<td><s:text name="Advertising Incentive" /></td>
<td></td>
<td><s:text name="Channel Placement Incentive" /></td>
<td></td>
</tr>
<s:iterator value="incentiveList" status="stat">
<tr>
<td><s:checkbox name="checkboxes[%{#stat.index}]" theme="simple" /></td>
<td></td>
<td><s:property value="pricingTierId" /> <s:hidden name="pricingTierId" value="%{incentiveList.pricingTierId}" /></td>
<td><s:property value="marketingAmount" /> <s:hidden name="marketingAmount" value="%{incentiveList.marketingAmount}" /></td>
<td></td>
<td><s:property value="marketingIncentive" /><s:hidden name="marketingIncentive" value="%{incentiveList.marketingIncentive}" /></td>
<td></td>
<td><s:property value="advertizingIncentive" /><s:hidden name="advertizingIncentive" value="%{incentiveList.advertizingIncentive}" /></td>
<td></td>
<td><s:property value="channelPlacementIncentive" /><s:hidden name="channelPlacementIncentive" value="%{incentiveList.channelPlacementIncentive}" /></td>
<td></td>
</tr>
</s:iterator>
</table>
<c:if test="${fn:length(incentiveList) == 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="true"/>
</c:if>
<c:if test="${fn:length(incentiveList) gt 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="false"/>
</c:if>
</s:form>
您没有在任何输入字段中使用name属性。这就是为什么它是空的。只需为输入字段指定name属性。aa也为这些字段添加s:hidden,就像您对其他字段所做的那样。Andrea请给我举个例子谢谢Praveen,但有一个问题,为什么在其他属性的隐藏名称中,value=“%{incentiveList.pricingTierId}”在很少的地方重复
<s:form target="_top" cssClass="table-controls form-wrapper" name="incentives" id="frmIncentives" action="saveIncentives.action" method="post">
<div id="actionErrors" style="color: red;">
<s:actionerror />
<s:fielderror />
</div>
<table id ="showIncentives" cellspacing="0" cellpadding="0" border="1" width="500" >
<tr style="font-weight: bold">
<td><s:checkbox name="Select All" id="select_all"
theme="simple" /></td>
<td>
<td></td>
<td></td>
<td><s:text name="Marketing Incentive" /></td>
<td></td>
<td><s:text name="Advertising Incentive" /></td>
<td></td>
<td><s:text name="Channel Placement Incentive" /></td>
<td></td>
</tr>
<s:iterator value="incentiveList" status="stat">
<tr>
<td><s:checkbox name="checkboxes[%{#stat.index}]" theme="simple" /></td>
<td></td>
<td><s:property value="pricingTierId" /> <s:hidden name="pricingTierId" value="%{incentiveList.pricingTierId}" /></td>
<td><s:property value="marketingAmount" /> <s:hidden name="marketingAmount" value="%{incentiveList.marketingAmount}" /></td>
<td></td>
<td><s:property value="marketingIncentive" /><s:hidden name="marketingIncentive" value="%{incentiveList.marketingIncentive}" /></td>
<td></td>
<td><s:property value="advertizingIncentive" /><s:hidden name="advertizingIncentive" value="%{incentiveList.advertizingIncentive}" /></td>
<td></td>
<td><s:property value="channelPlacementIncentive" /><s:hidden name="channelPlacementIncentive" value="%{incentiveList.channelPlacementIncentive}" /></td>
<td></td>
</tr>
</s:iterator>
</table>
<c:if test="${fn:length(incentiveList) == 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="true"/>
</c:if>
<c:if test="${fn:length(incentiveList) gt 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="false"/>
</c:if>
</s:form>