I'm doing a form in jsp that I can edit and delete at the same time, I have a problem with the option to delete several, where I have put a checkbox to each one to select the ones you want and delete them at the same time. The problem I have is that I can only put or the option to edit or delete all to work well, because if I put the key to close the for of people before closing the form only collects me the first record and if I put the key after closing the form the delete several button is repeated ... has someone done something similar and found a solution?
Jsp code
<%
if (session.getAttribute("ListaPersonas") != null) {
ArrayList<Persona> list = (ArrayList) session.getAttribute("ListaPersonas");
if (list.size() > 0) {
Persona per;
for (int i = 0; i < list.size(); i++) {
per = list.get(i);
%>
<form name="formusu" action="../Controlador.jsp" method="post">
<input type="text" name="id_dep" value="<%out.print(per.getId_departamento());%>" hidden>
<table class="table">
<thead>
<tr>
<th scope="col">Dni </th>
<th scope="col">Nombre </th>
<th scope="col">Apellidos</th>
<th scope="col">Email</th>
<th scope="col">Departamento</th>
<th scope="col">Cambiar Departamento</th>
<th scope="col">Modificar</th>
<th scope="col">Eliminar</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="dni" value="<%out.print(per.getDni());%>" required></td>
<td><input type="text" name="nombre" value="<%out.print(per.getNombre());%>" required>
<td><input type="text" name="apellidos" value="<%out.print(per.getApellidos());%>" required></td>
<td><input type="email" name="mail" value="<%out.print(per.getEmail());%>" required></td>
<td><input type="text" name="nombredepar" value="<%out.print(per.getNombre_departamento());%>" readonly></td>
<%
if (session.getAttribute("departamentos") != null) {
ArrayList<Departamento> listaDep = (ArrayList) session.getAttribute("departamentos");
if (listaDep.size() > 0) {
%>
<td>Elige Departamento: <SELECT NAME="departselecc">
<%
for (int j = 0; j < listaDep.size(); j++) {
%>
<!-- selected="< %if(i==0){out.print("true");}%>" -->
<OPTION VALUE="<%=listaDep.get(j).getId_departamento()%>"><%=listaDep.get(j).getNombre_departamento()%>
<%
}
}
}
%>
</SELECT>
</td>
<td><input type="submit" class="btn btn-primary" name="modificarusudire" value="Modificar"></td>
<td><input type="checkbox" id="borrarvariasper" name="borrarvariasper" value="<%out.print(per.getDni());%>"/></td>
</tr>
</tbody>
</table>
<%
// } si cierro aquí el for, me funciona bien el botón de borrar varios con los checkbox, pero al editar las personas solo me recoge el primer registro
%>
<div class="container text-center">
<br><input type="submit" class="btn btn-primary" name="borrarpers" value="Eliminar Varios">
</div>
</form>
<%
}
}
}
%>