JSP页面例子:
<%@ page language="java" pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<title>无标题文档</title>
<script>
var check=true;
function check_all(){
if(check==false){
arr = document.getElementsByName("checkbox");
for(i=0;i<arr.length;i++){
arr[i].checked = false
}
check=true;
}
else{
arr = document.getElementsByName("checkbox");
for(i=0;i<arr.length;i++){
arr[i].checked = true
}
check=false;
}
}
</script>
</head>
<body>
<form action="" method=""post >
<input type="checkbox" name="checkbox" value="0" onclick='check_all();'/>
全选 <a href="../xtyhgl/delAllyg.do">删除</a>
<table width="200" border="1" cellspacing="0" cellpadding="0">
<tr>
<td><input type="checkbox" name="checkbox" value="100001"/></td>
<td>100001</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="100003"/></td>
<td>100003</td>
</tr>
</table>
</form>
</body>
</html>
Action中代码:
如果是struts1.2在form类中定义属性 private String[] checkbox;
并为属性checkbox提供set和get方法。
如果是struts2 定义属性 private String[] checkbox;
并为属性checkbox提供set和get方法。
strust1:在action中获取form类中的值:String[] checkbox=request.getParameterValues("checkbox");这样在struts action中就获取了jsp中checkbox的值,循环取出。
strust2:在action中直接拿String[] checkbox的值,循环取出。本回答被提问者采纳