How to get checked checkboxes in JSP

Your checkbox has currently no value associated with the parameter name at all:

<input type="checkbox" name="chkBox">

So it's hard to find out the checked ones. You need to give the checkbox a value which uniquely identifies the selected item. In your particular example, the student ID seems to be an obvious choice:

<input type="checkbox" name="selected" value="${student.studentID}"> 

(by the way, why are you duplicating the entity name in the property name? why not just name it id so that you can just self-documentary use ${student.id}? also your var="students" is kind of odd, it is referring only one student, so just name it var="student"; the ${studentList} can better be named ${students})

When the form is submitted, all checked value are available as follows:

String[] selectedStudentIds = request.getParameterValues("selected");

Finally, just pass it through to your DAO/service class which does the business job:

studentService.delete(selectedStudentIds);

See also:

  • How to transfer data from JSP to servlet when submitting HTML form
  • ServletRequest.getParameterMap() returns Map<String, String[]> and ServletRequest.getParameter() returns String?
  • Send an Array with an HTTP Get

Tags:

Checkbox

Jsp

Jstl