<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>js test</title>
</head>
<script type="text/javascript" src="js/jquery-1.6.4.js"></script>
<script type="text/javascript">
function selectAll(){
var name=document.getElementsByName('checkbox');
for(var i=0;i<name.length;i++){
if(name.item(i).checked==false)
name.item(i).checked=true;
}
}
</script>
<body>
<form name="myForm" method="post" action="CheckValue">
全选:<input type="radio" name="all" id="all" onclick="selectAll('checkebox')" /><br/>
表单名称1: <input type="checkbox" name="checkbox" value="checkbox1" /><br/>
表单名称2: <input type="checkbox" name="checkbox" value="checkbox2" /><br/>
表单名称3: <input type="checkbox" name="checkbox" value="checkbox3" /><br/>
表单名称4: <input type="checkbox" name="checkbox" value="checkbox4" /><br/>
表单名称5: <input type="checkbox" name="checkbox" value="checkbox5" /><br/>
表单名称6: <input type="checkbox" name="checkbox" value="checkbox6" /><br/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>abs</display-name>
<servlet>
<servlet-name>CheckValue</servlet-name>
<servlet-class>org.abin.lee.servlet.CheckValue</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CheckValue</servlet-name>
<url-pattern>/CheckValue</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
package org.abin.lee.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CheckValue extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String[] value=req.getParameterValues("checkbox");
for(int i=0;i<value.length;i++){
System.out.println("第"+i+"个:"+value[i]);
}
}
}