javaweb 用戶註冊和登錄頁面

在此之前,我們需要先了解基礎知識.
一、我們先了解一下JSP隱含對象?
JSP隱含對象是Web容器創建的一組對象
JSP隱含對象的名稱是JSP的保留字
JSP隱含對象是可以直接在JSP頁面使用的對象,無需使用"new"獲取實例

二、JSP隱含對象
在這裏插入圖片描述
在這裏插入圖片描述
三、request對象
request對象主要用於處理客戶端請求,當瀏覽器請求一個網頁,會發送大量信息到web服務器,這些信息不能直接讀取,因爲信息是作爲HTTP請求頭的一部分傳輸到服務器,但是可以通過request對象提供的方法來獲取客戶端提交個服務器的信息.

request對象常用方法
在這裏插入圖片描述
1.接下來我們來實現註冊功能.

<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020/3/28
  Time: 16:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>註冊</title>
</head>
<body>
<h3 style="text-align: center">用戶註冊</h3>
<form name="frmRegister" action="do_register.jsp" method="post">
    <table border="1" cellpadding="10" style="margin: 0px auto">
        <tr>
            <td align="center">用戶名</td>
            <td><input type="text" name="username"></td>
        </tr>

        <tr>
            <td align="center">密碼</td>
            <td><input type="text" name="password"></td>
        </tr>
        <tr>
            <td align="center">從哪裏知道本網站</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 align="center"></td>
            <td colspan="2">
                <input type="submit" value="提交">
                <input type="reset"  value="重置">
            </td>
        </tr>
    </table>

</form>
</body>
</html>

(2)處理註冊頁面

<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020/3/28
  Time: 16:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>註冊</title>
</head>
<body>
<h3 style="text-align: center">用戶註冊</h3>
<form name="frmRegister" action="do_register.jsp" method="post">
    <table border="1" cellpadding="10" style="margin: 0px auto">
        <tr>
            <td align="center">用戶名</td>
            <td><input type="text" name="username"></td>
        </tr>

        <tr>
            <td align="center">密碼</td>
            <td><input type="text" name="password"></td>
        </tr>
        <tr>
            <td align="center">從哪裏知道本網站</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 align="center"></td>
            <td colspan="2">
                <input type="submit" value="提交">
                <input type="reset"  value="重置">
            </td>
        </tr>
    </table>

</form>
</body>
</html>

啓動服務器查看

在這裏插入圖片描述
在這裏插入圖片描述

給表單註冊頁面添加表單效驗,要求用戶名與密碼非空.
設置表單元素id屬性爲了給頁面javaScript代碼能訪問該元素,設置表單元素name屬性是爲了表單處理頁面能夠通過request.getParameter()方法獲取到表單元素的值.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章