jsp用户注册简单实例

要求

编程实现用户的注册功能

注册信息包括:用户名、密码、爱好

页面提示后,显示用户输入的数据

注册页面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
在这里插入图片描述

发布了33 篇原创文章 · 获赞 22 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/JY_WD/article/details/100610674
今日推荐