action如何接收js传来的checkbox值!
偏偏是晓强 2012-04-30 10:14:59 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function(){
$("#but").click(function(){
var str="";
var sel=document.getElementsByName("box"); //获取checkbox的值
for( var i=0;i<sel.length;i++)
if(sel[i].checked==true)
str+=sel[i].value;
if(str==""){
alert("请至少选择一条记录");
return false;
}
if(window.confirm("确定删除吗?")){
window.location.href= "del.action?user.userId="+str;
}
});
});
</script>
</head>
<body>
<center>
<table border="0" width="550px">
<tr bgcolor="#CCCCCC">
<th><input type="button" value="删除/批量" id="but"></th><th>编号</th><th>标题</th><th>性别</th><th>联系电话</th><th>邮箱地址</th>
</tr>
<s:iterator value="list">
<tr>
<td><input type="checkbox" name="box" value="${userId }"/></td>
<td><s:property value="userId"/></td>
<td><s:property value="userName"/></td>
<td><s:property value="userSex"/></td>
<td><s:property value="userPhone"/></td>
<td><s:property value="email"/></td>
</tr>
</s:iterator>
</table>
</center>
</body>
</html>
action调用:
public boolean delUser(Connection conn ){
try {
HttpServletRequest request = ServletActionContext.getRequest();
String sql = "delete from Users where userId in (?)";
ps = conn.prepareStatement(sql);
ps.setObject(1, ...);
ps.executeUpdate();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
action如何接收js传来的checkbox值呢!都说用HttpServletRequest request = ServletActionContext.getRequest();可以接收,可是我试了好多怎么就不行呢!