为什么用request.getParameter()接收单选按键radio和复选框checkbox信息时,收到的值不对呢?
(1)信息输入
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="例五展示.jsp" method="post">
<table>
<tr>
<td>姓名:<input type="text" name="strname" ></td>
</tr>
<tr>
<td>密码:<input type="password" name="strpassword">(必填)</td>
</tr>
<tr>
<td>请再次输入密码: <input type="password" name="strpassword1"></td>
</tr>
<tr>
<td>性别: <input type="radio" name="strsex" /> 男
<input type="radio" name="strsex" /> 女</td>
</tr>
<tr>
<td>爱好: <input type="checkbox" name="hobby" checked/> 篮球
<input type="checkbox" name="hobby" > 足球
<input type="checkbox" name="hobby" > 乒乓球
<input type="checkbox" name="hobby" > 羽毛球
</td>
</tr>
<tr>
<td>星座: <select name="xingzuo">
<option>金牛</option>
<option>巨蟹</option>
<option>射手</option>
<option>双子</option>
<option>白羊</option>
<option>狮子</option>
<option>处女</option>
<option>摩羯</option>
<option>双鱼</option>
<option>天平</option>
<option>水瓶</option>
<option>天蝎</option>
</select></td>
</tr>
<tr>
<td>个人简介<textarea name="jieshao" wrap="off">
</textarea>
</td>
</tr>
<tr>
<td><input type="submit" value="确定"></td>
</tr>
</table>
</form>
</body>
</html>
(2)信息显示
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String NAME=request.getParameter("strname");
String PASSWORD=request.getParameter("strpassword1");
String SEX=request.getParameter("strsex");//单选按键
String HOBBY[]=request.getParameterValues("hobby");//复选框数组
String XINGZUO=request.getParameter("xingzuo");
String JIESHAO=request.getParameter("jieshao");
%>
<form >
<table>
<tr>
<td>您的姓名:<%=NAME %></td>
</tr>
<tr>
<td>您的密码:<%=PASSWORD %>(必填)</td>
</tr>
<tr>
<td>您的性别:<%=SEX %></td>
</tr>
<tr>
<td>您的爱好:<%
int i=0;
for(String s:HOBBY){%>
<%out.print(HOBBY[i]); %>
<%} %>
</td>
</tr>
<tr>
<td>您的星座:<%=XINGZUO %></td>
</tr>
<tr>
<td>您的个人简介:<%=JIESHAO %></td>
</tr>
</table>
</form>
</body>
</html>
运行结果
求解答疑惑