JSP删除增加的问题
新手上路,做个表格,没有连接数据库
首先,我表格里有10条数据
public class VMDB {
static List<Student> stus = new ArrayList<Student>();
static {
stus.add(new Student(1,"刘睿","1234"));
stus.add(new Student(1,"刘睿","1234"));
stus.add(new Student(1,"刘睿","1234"));
stus.add(new Student(1,"刘睿","1234"));
stus.add(new Student(1,"刘睿","1234"));
stus.add(new Student(1,"刘睿","1234"));
stus.add(new Student(1,"刘睿","1234"));
stus.add(new Student(1,"刘睿","1234"));
stus.add(new Student(1,"刘睿","1234"));
stus.add(new Student(1,"刘睿","1234"));
}
public static List<Student> findAll(){
return stus;
}
通过stus传的,然后通过java页面的request传到jsp页面去
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws
ServletException,
IOException {
req.setAttribute("abc",VMDB.findAll() );
req.getRequestDispatcher("/list.jsp").forward(req, resp);
jsp页面是这么接收的
List<Student> stus =(List<Student>) request.getAttribute("abc") ;
我就是想问,我表格是想通过选择复选框删除,可以选择多个,我看过网上的说吧name设置为一样的,再接收,接收之后呢?然后这个不在jsp页面,在java页面可以写吗?最好给个简易的代码。增加一个用户,用什么增加,这个我是新手,不太明白,虽然学过C语言,但是觉得和java不一样
------解决方案--------------------算了,在这里给你把!
VMDB
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class VMDB {
static List<Student> stus = new ArrayList<Student>();
static {
for(int i = 0 ; i < 10 ; i++){
stus.add(new Student(i, "刘睿" + i, "123" + i));
}
}
public static List<Student> findAll() {
return stus;
}
public static void add(Student s){
stus.add(s);
}
public static void deleteById(Integer id){
Iterator<Student> it = stus.iterator();
while(it.hasNext()){
Student s = it.next();
if(s.getId().equals(id)){
it.remove();
}
}
}
}