checkbox.html
<!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>Insert title here</title>
<style type="html/css">
<!--
.STYLE1{
font-site:large;
}
-->
</style>
</head>
<body>
<form name="form1" action="checkbox.jsp" method="post">
<span class="STYLE1">组合框<br />
<input type="checkbox" name="checkbox" value="red" checked="checked"/><font color="red">red</font><br/>
<input type="checkbox" name="checkbox" value="green"/><font color="green">green</font><br/>
<input type="checkbox" name="checkbox" value="blue"/><font color="blue">blue</font><br/>
<input type="checkbox" name="checkbox" value="other"/><font color="auto">other</font><br/>
</span>
<hr />
<!-- name属性在request对象中取值时使用 -->
<input name="ok" type="submit" value="提交">
</form>
</body>
</html>
checkbox.jsp
<%@ 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>Insert title here</title>
</head>
<body>
<h3>您选择的为:</h3>
<h2>
request.getCharacterEncoding("UTF-8");
</h2>
<%
String[] color=request.getParameterValues("checkbox");
for(int i=0;i<color.length;i++)
{
if(color[i].equals("red"))
out.print("<font color=\"red\">");
else if(color[i].equals("green"))
out.print("</font color=\"green\">");
else if(color[i].equals("blue"))
out.print("<font color=\"blue\">");
else out.print("<font color=\"auto\">");
out.print(color[i]);
out.print("</font>");
out.print("<br/>");
}
%>
</body>
</html>