1、 将前台jsp页面中的所有你要用到checkbox的name值设为相同
<input type="checkbox" name="userid">
然后在后台获取参数时使用:
String userid[] = request.getParameterValues("userid");
String userIdAll = "";
if (userid!=null) {
for(int i=0;i<userid.length;i++)
{
userIdAll =userIdAll + userid + "," ;
}
userIdAll = userIdAll.substring(0, userIdAll.length-1 )
String sql = "delete reguser where userid in(" + userIdAll+ ")";
//执行sql语句略......
}
2、String[] box = request.getParameterValues("checkbox");//取得ID数组,checkbox放ID值;
int[] UserID = ExStr.strArray2IntArray(box);//如有必要转换成int数组,ExStr是我自己定义的字符串处理的类;
再调用delete的sql语句……
3、就用简单的sql语句就可以实现了。
String id = request.getParameter("id");
String sql = "delete from table where id in ("+ id +");
servlet,jsp批量删除
最新推荐文章于 2023-02-05 23:25:52 发布