在Servlet端獲取jsp頁面選中的checkbox值
阿新 • • 發佈:2019-02-14
JSP中,在Servlet端獲取jsp頁面的checkbox的值,如圖:
Jsp程式碼:
<table id="tabquery" cellpadding="1" cellspacing="1" border="1"> <thead> <tr> <th><input id="chkAll" type="checkbox" /></th> <th>員工姓名</th> <th>婚姻狀態</th> <th>是否在崗</th> <th>員工類別</th> <th>所在部門</th> <th>出勤明細</th> <th>住址</th> <th>操作</th> </tr> </thead> <tbody> <tr> <td><input name="chkItem" type="checkbox" value="0001" /></td> <td>李煜</td> <td>已婚</td> <td>否</td> <td>正式員工</td> <td>研發部門</td> <td><a href="" value=0001>明細</a></td> <td>學府路1號</td> <td><a href="EditEmployeeInfoServlet?emp_id=0001">編輯</a></td> </tr> <tr> <td><input name="chkItem" type="checkbox" value="0002" /></td> <td>李四</td> <td>已婚</td> <td>是</td> <td>試用員工</td> <td>市場部門</td> <td><a href="" value=0002>明細</a></td> <td>南部商務區,健宸大廈1101</td> <td><a href="EditEmployeeInfoServlet?emp_id=0002">編輯</a></td> </tr> <tr> <td><input name="chkItem" type="checkbox" value="638f94b0095b4841ac3af6b27eada793" /></td> <td>黃小琥</td> <td>未婚</td> <td>是</td> <td>正式員工</td> <td>市場部門</td> <td><a href="" value=638f94b0095b4841ac3af6b27eada793>明細</a></td> <td>上海浦東新區891號</td> <td><a href="EditEmployeeInfoServlet?emp_id=638f94b0095b4841ac3af6b27eada793">編輯</a></td> </tr> <tr> <td><input name="chkItem" type="checkbox" value="0004" /></td> <td>李四</td> <td>已婚</td> <td>是</td> <td>試用員工</td> <td>研發部門</td> <td><a href="" value=0004>明細</a></td> <td>寧波四明中路887</td> <td><a href="EditEmployeeInfoServlet?emp_id=0004">編輯</a></td> </tr> <tr> <td><input name="chkItem" type="checkbox" value="0005" /></td> <td>李四</td> <td>已婚</td> <td>否</td> <td>試用員工</td> <td>市場部門</td> <td><a href="" value=0005>明細</a></td> <td>北京中關村無底洞</td> <td><a href="EditEmployeeInfoServlet?emp_id=0005">編輯</a></td> </tr> </tbody> </table>
Servlet中程式碼:
String[] item = request.getParameterValues("chkItem");
String delStr = "";
for(int i=0;i<item.length;i++)
delStr+=item[i]+",";
System.out.println(delStr);