Click here to Skip to main content
11,721,053 members (82,935 online)
Rate this: bad
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 4:11am
Edited 7-Jul-13 6:52am

1 solution

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

Solution 1

int userId = Integer.parseInt(userID[i]); 
kellycx at 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
0 Sergey Alexandrovich Kryukov 500
1 OriginalGriff 334
2 Mika Wendelius 160
3 F-ES Sitecore 140
4 Maciej Los 80
0 Sergey Alexandrovich Kryukov 2,199
1 OriginalGriff 959
2 F-ES Sitecore 640
3 Maciej Los 609
4 Richard MacCutchan 540

Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2015
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