我正在学习Jsp和servlet。在我的jsp我正在返回一个员工表,我试图通过userId从复选框中删除多行。当我运行servlet时,我填写了员工表,但是通过复选框,我只能删除第一个员工(第一行),其他每个人都返回null ... 我认为每一行都创建了新的复选框,因此名称不是唯一的,它只传递第一个参数..
<div class ="removeBtn"> <!-- remove button for multiple delete -->
<input type="submit" value="Remove selected" form="multipleDeleteRowsId">
</div>
<table class="employeeInfoTable" >
<tr>
<th></th>
<th>First Name</th>
<th>Second Name</th>
<th>Last Name</th>
<th>Date of Join</th>
<th>Branch</th>
<th>Action</th>
</tr>
<c:forEach var="tempUser" items="${employeesList}">
<c:url var="idLink" value="EmployeeControllerServlet">
<c:param name="command" value="LOAD"/>
<c:param name="employeeID" value="${tempUser.id}"/>
</c:url>
<c:url var="removeLink" value="EmployeeControllerServlet">
<c:param name="command" value="DELETE"/>
<c:param name="deleteByID" value="${tempUser.id}"/>
</c:url>
<tr>
<td>
<form action="EmployeeControllerServlet" method="get" id="multipleDeleteRowsId" > <!-- here is multiple delete -->
<input type="hidden" name="command" value="DELETE">
<input type="checkbox" name="selectedRow" value="${tempUser.id}">${tempUser.id}
</form>
</td>
<td>${tempUser.firstName}
</td>
<td>${tempUser.surname}
</td>
<td>${tempUser.lastName}
</td>
<td>${tempUser.dateOfJoin}
</td>
<td>${tempUser.branch}
</td>
<td>
<ul id="menu">
<li><a href="#">Edit</a>
<ul>
<li><a href="#"><a href="${idLink}">More Info</a></a></li>
<li><a href="#"><a href="${removeLink}"
onclick="return confirm( 'Are you sure you want to delete?')">Remove</a></a>
</li>
</ul>
</li>
</ul>
</td>
</tr>
</c:forEach>
</table>
这里是servlet
private void deleteUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
String[] selected = request.getParameterValues("selectedRow");
for(int i = 0; i<selected.length; i++){
System.out.println(" " + selected[i] + " ");
}
} catch (Exception e) {
System.out.println("not deleted ? " + e.getCause());
}
}
最后得到的结果首先是null ..
提前致谢