新手问jsp如何处理表单数组
比如表单里有以下内容:
<input type= "checkbox " name= "article_id[] " id= "article_id ">
<input type= "checkbox " name= "article_id[] " id= "article_id ">
<input type= "checkbox " name= "article_id[] " id= "article_id ">
处理页面如何处理它并把它转换成用“,”分割的字符串?
比如php是这样的
$article=$_POST[ 'article_id '];
foreach($article as $id){
$str.=$id. ", ";
}
$str=substr($str,0,-1);
$sql= "update .........where id in( ".$str. ") ";
........
------解决方案-------------------- <input type= "checkbox " name= "article_id ">
<input type= "checkbox " name= "article_id ">
<input type= "checkbox " name= "article_id ">
jsp:
String[] params = request.getParameterValues( "article_id ");
String sql = "update .........where id in ( "+splitID(params)+ ") ";
public String splitID(String id[]){
StringBuffer str = new StringBuffer();
for(int i=0;i <id.length;i++){
if(i> 0)
str.append( ", ");
str.append(id[i]);
}
return str.toString();
}
------解决方案--------------------String[] params = request.getParameterValues( "article_id ");
StringBuffer str = new StringBuffer();
for(int i=0;i <params .length;i++){
if(i> 0)
str.append( ", ");
str.append(params [i]);
}
String sql = "update .........where id in ( "+str.toString()+ ") ";