Click here to Skip to main content
12,071,956 members (61,495 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java JSP Servlet
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();
					DAOManager mgr = new DAOManager();

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());
		return true;
		} catch (Exception e) {
		return false;

JSP code:
DAOManager mgr = new DAOManager();
User[] users = mgr.getAllUsers();
for(int i = 0; i < users.length; i++)
													type="checkbox" name="deleteUser"
												<td><%=users[i].getUserName()%></td>										</tr>
Posted 7-Jul-13 5:11am
Edited 7-Jul-13 7:52am

1 solution

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

Solution 1

int userId = Integer.parseInt(userID[i]); 
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
Web03 | 2.8.160208.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2016
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