多选框都用一个名字,比如
<input type="checkbox" name="chk">
到后台用String[] data = request.getParameterValues("chk");
然后读data数组的值
if (data != null){
  for(int i = 0; i < data.length; i++) {
    sql = "delete from table where id='" + data[i] + "'";
    stmt.executeUpdate (sql);
  }
}
选上的自然都被删除了

解决方案 »

  1.   

    多选框名字取一样的(checkname),每个多选框的VALUE取记录的ID,然后提交,用getParameterValues(checkname),再循环读取记录ID,逐个删除。
      

  2.   

    function btnDelete_onclick()
    {
    var arrDel = document.getElementsByName("checkboxname");
    var arrID = new Array(arrDel.length)
    for (var i=0;i<arrDel.length;i++)
    arrID[i] = arrDel[i].value;
    form1.deleteall.value=arrID.join();
    form1.action="deleteall.jsp";
    form1.submit();
    return false;
    }</SCRIPT>
    <form name=form1>
    <input type=checkbox name=checkboxname value="id1">
    <input type=checkbox name=checkboxname value="id2">
    <input type=checkbox name=checkboxname value="id3">
    <input type=checkbox name=checkboxname value="id4">
    <input type=hidden name=deleteall>
    <INPUT type="submit" value="Button" id=btnDelete name=btnDelete LANGUAGE=javascript onclick="return btnDelete_onclick()">
    </form>
      

  3.   

    while(rs.next()){
    <td><INPUT TYPE="checkbox" NAME="id" value="<%=数据库中的唯一标识%>"></td>
    ....
    }String[] str=request.getParameterValues("id");
    String strSQL="delete from tablename where";
    for(int i=0;i<str.length-1;i++)
      {
    strSQL = strSQL + " id='"+str[i]+"' or";
      }
    strSQL = strSQL + " id='"+strid[str.length-1]+"'";在前台判断一下,不能不选!
      

  4.   

    楼上的不太好,checkbox 用同名比较好如:fruits
    例子:
    String[] Parm = request.getParameterValues("fruits");
    if (Parm!=null &&  Parm.length  !=  0 )
      {
      while(i < Parm.length )
      {
        String[] splitstring =com.strToArray(Parm[i],"/") ;//strToArrays是个string to Arrays 的javabean 用来拆分多个主键的
        while(j < splitstring.length ){
          if (deleteplus==""){
                deleteplus = deleteplus +"asp ="+" '"+splitstring[j]+"'";
                }
                else
                {
                deleteplus = deleteplus +" and asp ="+" '"+splitstring[j]+"'";
                }
          j++;
        }
        j = 0;
      i++;}
      deleteplus ="where  "+ deleteplus;
      delete = delete + deleteplus;
      out.println(delete);
      try
      {
            stmt.executeUpdate(delete);
            stmt.close();
                           %>
                            <br>删除成功!
                            <%
        }
                    catch(SQLException e)
                    {
                            out.println("SQLException: " + e);
                    }  }