html代码如下
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>多变量提交</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="post" action="multiChoice" >
<input type="checkbox" name="checkbox1" value="西瓜">
西瓜
<input type="checkbox" name="checkbox1" value="香蕉" >
香蕉
<input type="checkbox" name="checkbox1" value="苹果">
苹果
<input type="checkbox" name="checkbox1" value="桃子">
桃子
<input type="submit" name="Submit" value="提交">
<input type="reset" name="reset" value="重置">
</form>
</body>
</html>
servlet代码如下: public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GB2312");
request.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
String [] paramValues=request.getParameterValues("checkbox1");
String temp=new String("");
for(int i=0;i<paramValues.length;i++)
temp+=paramValues[i]+" ";
out.println("您喜欢的水果商:"+temp);
}调试的时候出现如图
图片地址:
http://photo.blog.sina.com.cn/photo/7cb1c50ega13e78106944
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>多变量提交</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="post" action="multiChoice" >
<input type="checkbox" name="checkbox1" value="西瓜">
西瓜
<input type="checkbox" name="checkbox1" value="香蕉" >
香蕉
<input type="checkbox" name="checkbox1" value="苹果">
苹果
<input type="checkbox" name="checkbox1" value="桃子">
桃子
<input type="submit" name="Submit" value="提交">
<input type="reset" name="reset" value="重置">
</form>
</body>
</html>
servlet代码如下: public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GB2312");
request.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
String [] paramValues=request.getParameterValues("checkbox1");
String temp=new String("");
for(int i=0;i<paramValues.length;i++)
temp+=paramValues[i]+" ";
out.println("您喜欢的水果商:"+temp);
}调试的时候出现如图
图片地址:
http://photo.blog.sina.com.cn/photo/7cb1c50ega13e78106944
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货