Click here to Skip to main content
12,998,654 members (130,335 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
How do I actually go about deleting multiple users using checkboxes? I have a page whereby it shows all created users with a checkbox beside each row created base on the number of created users. For now, I am only able to delete one checkbox at a time.

I understand that for multiple deletion, i need to make use of String []. But my code only does grabs the first checkbox to delete.

My servlet code:
String []userID = request.getParameterValues("deleteUser");
				
				
				for(int i=0;i<userID.length;i++){
					int userId = Integer.parseInt(request.getParameter("deleteUser")); 
					User users = new User();
					users.setUserID(userId);
					DAOManager mgr = new DAOManager();
					mgr.deleteUsers(users);
					response.sendRedirect("reg.jsp");


DAO Code:
public boolean deleteUsers(User user)
	{
		String sql = "DELETE FROM user WHERE userID=?";
		try {
		
		Connection conn = getConnection();
		
		PreparedStatement ps = conn.prepareStatement(sql);
		
		ps.setInt(1, user.getUserID());
		
		ps.executeUpdate();
		return true;
		} catch (Exception e) {
		e.printStackTrace();
		return false;
		}
		}


JSP code:
	<%
DAOManager mgr = new DAOManager();
User[] users = mgr.getAllUsers();
for(int i = 0; i < users.length; i++)
 {
%>
										<tr>
												<td><input
													type="checkbox" name="deleteUser"
													value=<%=users[i].getUserID()%>></td>
												<td><%=users[i].getUserID()%></td>
												<td><%=users[i].getUserName()%></td>										</tr>
										
										<%
}
%>
 
Posted 7-Jul-13 4:11am
kellycx745
Updated 7-Jul-13 6:52am
v3

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

int userId = Integer.parseInt(userID[i]); 
  Permalink  
Comments
kellycx 8-Jul-13 11:16am
   
Thank you so much Shubhashish! It worked!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 11 Feb 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100