要求
編程實現用戶的注冊功能
注冊信息包括:用戶名、密碼、愛好
頁面提示后,顯示用戶輸入的數據
注冊頁面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