基于jsp和servlet,通过复选框实现批量删除的功能

复选框实现批量删除

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>




Insert title here
 
   
























姓名城市通讯录修改
${item.username }${item.cityname }通讯录修改
增加






后台的servlet

public class UserDeleteServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}


/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//处理乱码
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");


PrintWriter out = response.getWriter();
String users[]=request.getParameterValues("check");//用数组接受前台传来的被选中的复选框的值
if(users!=null){
UserDao userDao=new UserDao();
TelDao telDao=new TelDao();
int m=0;
int n=0;
for(int i=0;i//循环删除被选中的数据
int id=Integer.parseInt(users[i]);
m=userDao.delete(id);
//删除一个用户,同时要删除他所属的通讯录(根据用户userid=id来删除)
//System.out.println(id);
//n=telDao.deleteTelByUser(id);
}

if(m>0){//成功
out.println("");
out.close();
}else{//失败
out.println("");
out.close();
}
}
}
}

你可能感兴趣的:(servlet,jsp,checkbox,批量删除)