要求
编程实现用户的注册功能
注册信息包括:用户名、密码、爱好
页面提示后,显示用户输入的数据
注册页面reginput.jsp
<%--
Created by IntelliJ IDEA.
User: 长风
Date: 2019/9/7
Time: 15:59
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>用户注册</title>
</head>
<body>
<form name="form1" method="post" action="reginfo.jsp">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" name="pwd"></td>
</tr>
<tr>
<td>爱好:</td>
<td><input type="checkbox" name="channel" value="唱歌">唱歌
<input type="checkbox" name="channel" value="跳舞">跳舞
<input type="checkbox" name="channel" value="足球">足球
<input type="checkbox" name="channel" value="羽毛球">羽毛球
</td>
</tr>
<tr>
<td>
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Reset" value="取消">
</td>
</tr>
</table>
</form>
</body>
</html>
信息读取显示页面reginfo.jsp
<%--
Created by IntelliJ IDEA.
User: 长风
Date: 2019/9/7
Time: 16:12
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>注册信息</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
// 设置支持中文字符的字符集
String name = request.getParameter("name");
// name=new String(name.getBytes("ISO-8859-1"),"GBK");
String pwd = request.getParameter("pwd");
String[] channels = request.getParameterValues("channel");
%>
你输入的注册信息:<br>
<table>
<tr>
<td>用户名:</td>
<td><%=name%>
</td>
</tr>
<tr>
<td>密码:</td>
<td><%=pwd%>
</td>
</tr>
<tr>
<td>爱好:</td>
<%
if (channels != null) {
for (int i = 0; i < channels.length; i++) {
%>
<td><%=channels[i]%>
</td>
<%
// out.println(channels[i]);
}
}
%>
</tr>
</table>
</body>
</html>
效果
2