2010.10.12——— checkbox提交 request.getParameterValues
request.getParameterValues用来处理checkbox的
需求很简单 就是一个table 有checkbox 选择一个或多个 然后删除
html如下
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_box" id="tblSort01">
<tr class="tr_top">
<td ></td>
<td >形象进度</td>
</tr>
<tr class="tr_1">
<td><input type="checkbox" name="cb" value="1" /></td>
<td>24%</td>
</tr>
<tr class="tr_1">
<td><input type="checkbox" name="cb" value="2" /></td>
<td>24%</td>
</tr>
<tr class="tr_1">
<td><input type="checkbox" name="cb" value="3" /></td>
<td>24%</td>
</tr>
<tr>
<td><input id="delete" value="删除"/></td>
</tr>
</table>
本来我是这样写的
js
var fid = "";
jQuery("#tblSort01 input:checked").each(function(i){
fid += jQuery(this).val();
if(i!= (jQuery("#tblSort01 input:checked").length-1))
fid += ",";
});
window.open("${pageContext.request.contextPath}/deleteGC_FXXX.action?id="+fid);
action
public String deleteGC_FXXX(){
HttpServletRequest request = ServletActionContext.getRequest();
String id = request.getParameter("id");
this.GC_FXXXService.deleteById(Integer.parseInt(id));
return SUCCESS;
}
后来 知道了 request.getParameterValues 修改如下:
js
jQuery("delete").click(function(){
document.ss.action = "${pageContext.request.contextPath}/deleteGCZBDLJG.action";
document.ss.submit();
});
在html外面套一层form表单 name="ss"
action:
public String deleteJZQYXX(){
HttpServletRequest request = ServletActionContext.getRequest();
String qybm[] = request.getParameterValues("checkbox");
for(int i = 0;i<qybm.length;i++){
this.QY_JZYService.deleteZZXXByQybm(qybm[i]);
this.QY_QYXXService.deleteByQybm(qybm[i]);
}
return SUCCESS;
}