<logic:iterate id="bean" name="beanList" >
<tr>
<td><input type = "checkbox" name = "ids" value = '<bean:write name = "bean" property = "id"/>'></td>
<td>.....</td>
</tr>
</logic:iterate>
<input type = "button" value = "全選" onclick = "for (var i = 0; i < delForm.questionIds.length; i ++){delForm.questionIds[i].checked = true;}"/>
<input type = "button" value = "反選" onclick = "for (var i = 0; i < delForm.questionIds.length; i ++){delForm.questionIds[i].checked = false;}"/>
<input type = "button" value = "刪除選中" onclick = "if(confirm('真的要刪除選中內容?'))delForm.submit()"/>
</form>
FormBean( 我使用的是DynaActionForm,所以在struts-config.xml中配置)
<form-bean name="testingForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="id" type="java.lang.String"/>
<form-property name="ids" type="java.lang.String[]"/>
........
</form-bean>
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// 獲取操作名
DynaActionForm dyna = (DynaActionForm) form;
// ids數組是所有被選中記錄的id值
String[] ids = (String[]) dyna.get("ids");
// 調用相應dao方法,完成刪除所有指定id操作
return mapping.findForward(".....");
}