如何向后去后传list 大家好,请教一个问题,我在前台页面做了一个批量删除,就是每条记录前面都有一个checkbox,就是我选几条记录后,如何把这些记录的ID都传入到后台的action呢?请大家帮帮忙,看看如何解决,谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 request.getParameterValues("checkbox名称"); 用数组接收 try{ idlist = (String[])event.getBody().get("id");//多条}catch(Exception fe){ idlist = new String[]{(String)event.getBody().get("id")};//单条}//event为HashMap对象 谢谢楼上的解答,不过我还是不太理解,event.getBody()是做什么用的啊 接着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,......) 不要找写好的代码啦,自己试着写一些嘛,做法是你可以用checkbox的一个方法selectedIndex,大概就是这个名字吧,不对的话google,这个方法会返回当前chexbox的所有选中的项的数组,得到数组了,相信其他的你会做了吧 页面:<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]); } 请教,jsp数组问题 java中怎样获得字符串中的符号个数 关于jsp中使用frame问题. 请教jsf的jsp页面运行时null错误的问题 Linux下开发web应用,应该是比较经典的问题?求助 我现在上好多网站都有这个错误?怎么回事? 我到底错在哪儿了,各位大侠,请指点一下我这个小学徒!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 兄弟想学习struts,有关于这方面的中文教材吗?e文学的不好 谁能给我JBuilder7.0的注册码啊? 请问这个SQL注入工具叫什么名儿? frame 内部提交 找不到JAR包
try{
idlist = (String[])event.getBody().get("id");//多条
}
catch(Exception fe){
idlist = new String[]{(String)event.getBody().get("id")};//单条
}
//event为HashMap对象
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,......)
做法是你可以用checkbox的一个方法selectedIndex,大概就是这个名字吧,不对的话google,这个方法会返回当前chexbox的所有选中的项的数组,得到数组了,相信其他的你会做了吧
<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]);
}