关于复选框计数,我有一个错误。我的数据旁边有一个复选框。例如,我勾选了2个复选框,然后按Delete键。它将始终显示为0。如何解决此错误?我尝试了几种方法来解决此问题,但我的计数始终显示为0。
This is a picture of the message display
String[] id = request.getParameterValues("deletechkbox");
int count=0;
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
// Step 2: Define Connection URL
String connURL = "jdbc:mysql://localhost/medicloud?user=root&password=root";
// Step 3: Establish connection to URL
conn = DriverManager.getConnection(connURL);
if (id != null)
{
for(int i=0; i<id.length; i++){
String sqlStr = "DELETE from exercise1 where id=?";
PreparedStatement pstmt = conn.prepareStatement(sqlStr);
pstmt.setInt(1, Integer.parseInt(id[i]));
int rec = pstmt.executeUpdate();
if (rec==1)
count++;
}
}
这是我的复选框设置。
<td style="width: 5%"><input class="mychkbox" type="checkbox"
value="<%=id%>" form="multipleDele" name="deletechkbox" /></td>
这是我的复选框表格
<form action="delete.jsp" id="multipleDele" method="post">
<strong>Selected Exercise(s) to: </strong><input type="submit"
value="Delete" id="mulDelBtn" name="deleteMultipleBtn" />
</form>