回复 2楼 wzh545394622
jsp:
<form action="studentsave" method="post">
<table border="1" bordercolor="#00FF00" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>选中</td>
<td>学号</td>
<td>名字</td>
<td>性别</td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="text" name="list[0].no" /></td>
<td><input type="text" name="list[0].name" /></td>
<td>
<select name="list[0].sex">
<option selected="selected">男</option>
<option>女</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="text" name="list[1].no" /></td>
<td><input type="text" name="list[1].name"/></td>
<td>
<select name="list[1].sex">
<option selected="selected">男</option>
<option>女</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="text" name="list[2].no"/></td>
<td><input type="text" name="list[2].name"/></td>
<td>
<select name="list[2].sex">
<option selected="selected">男</option>
<option>女</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="提交"/></td>
<td colspan="2" align="left"><input type="reset" value="重置" /></td>
</tr>
</table>
</form>
action:
public class StudentAction extends ActionSupport {
//用list集合接收前台的数据
List<Student> list=null;
//批量存储学生对象
public String listsave(){
//遍历判断是否为空,如果为空,删除该元素
Iterator iter=list.iterator();
while(iter.hasNext()){
Student student=(Student)iter.next();
if(student.getSno()==0){
iter.remove();
}
}
StudentDao dao=new StudentDao();
boolean isright=dao.saveManyStudent(list);
if(isright){return SUCCESS;}
return ERROR;
}
省略set、get方法
}
----------------------------
前台有3行可填,即可输入三个学生信息,假如输入小于三个,后台报错。