大家好,请教一个问题,我在前台页面做了一个批量删除,就是每条记录前面都有一个checkbox,
就是我选几条记录后,如何把这些记录的ID都传入到后台的action呢?请大家帮帮忙,看看如何解决,谢谢。

解决方案 »

  1.   

    request.getParameterValues("checkbox名称");
      

  2.   

    用数组接收
     
    try{
      idlist = (String[])event.getBody().get("id");//多条
    }
    catch(Exception fe){
      idlist = new String[]{(String)event.getBody().get("id")};//单条
    }
    //event为HashMap对象
      

  3.   

    谢谢楼上的解答,不过我还是不太理解,event.getBody()是做什么用的啊
      

  4.   

    接着3楼写:这种方法实用于checkbox名称重复多次的情况String[] ids = request.getParameterValues("checkbox名称");
    String sql = "delete from table where id in(";
    for(int i = 0;i < ids.length;i++){
        sql += ids[i] + ",";
    }if(ids.length > 0){
        sql = sql.subString(0,sql.length() - 1);
    }
    sql += ")";// 执行sql
    // 组合好的sql代码如下:
    // delete from table where id in(1,2,3,4,......)
      

  5.   

    不要找写好的代码啦,自己试着写一些嘛,
    做法是你可以用checkbox的一个方法selectedIndex,大概就是这个名字吧,不对的话google,这个方法会返回当前chexbox的所有选中的项的数组,得到数组了,相信其他的你会做了吧
      

  6.   

    页面:
    <form name="f1" action="myServlet?param=abc" method="post">
    <input type="text" name="param">
    <input type="checkbox" name="id" value="1">
    <input type="checkbox" name="id" value="2">
    <input type="checkbox" name="id" value="3">

    <input type="submit" value="Submit" />
    </form> 
    后台:
    String [] id = request.getParameterValues("id");
    for(int i=0;i<id.length;i++){
    System.out.println("id["+i+"]="+id[i]);
    }