处理 struts 未选中的复选框

handle struts unchecked checkbox

事实是 struts 不会处理未经检查的 checkbox.I 得到一个 problem.Set bean 类型是 InfoForm 并且 recommend 字段关联一个复选框。在控制器 A 中,将 recommend 字段设置为值 1,意味着加载页面时应选中该复选框。加载页面后,我单击复选框并将复选框设置为未选中。接下来,我将表单提交给 Controller.But 中的方法,recommend 字段值将为 1,因为 struts 选中了复选框未选中状态,然后将不对其进行任何操作,并且recommend 字段值回传到后面end.How 可以处理吗?

我是这样解决的:

<script>
$(function () {
$('.ckbox').each(function () {
    var next = $(this).next('input[type="hidden"]');
    if (next.val() == 1)
        this.checked = true;
    else
        this.checked = false;
})
$(".ckbox").bind('change', function () {
    var next = $(this).next('input[type="hidden"]');
    if (this.checked == true)
        next.val(1);
    else
        next.val(0);

})
});
</script>


<input type="checkbox" class="ckbox"/>recommend
<input type="hidden" name="infoBeanForm.recommend" value="${(infoBeanForm.recommend)!0}"/>

<input type="checkbox" class="ckbox"/>
<input type="hidden" name="infoBeanForm.clientType" value="${infoBeanForm.clientType[0]!0}"/>
android
&nbsp;&nbsp;&nbsp;
<input type="checkbox" class="ckbox"/>
<input type="hidden" name="infoBeanForm.clientType" value="${infoBeanForm.clientType[1]!0}"/>
ios