最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java?Web應用小案例之實現(xiàn)用戶登錄功能全過程

 更新時間:2024年01月18日 15:49:18   作者:howard2005  
在Java開發(fā)過程中實現(xiàn)用戶的注冊功能是最基本的,這篇文章主要給大家介紹了關(guān)于Java?Web應用小案例之實現(xiàn)用戶登錄功能的相關(guān)資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下

零、本節(jié)學習目標

  • 掌握純JSP方式實現(xiàn)用戶登錄功能
  • 掌握JSP+Servlet方式實現(xiàn)用戶登錄功能
  • 掌握JSP+Servlet+DB方式實現(xiàn)用戶登錄功能
  • 掌握MVC模式實現(xiàn)用戶登錄功能

一、純JSP方式實現(xiàn)用戶登錄功能

(一)實現(xiàn)思路

登錄頁面login.jsp,輸入用戶名和密碼后,跳轉(zhuǎn)到登錄處理頁面doLogin.jsp進行業(yè)務邏輯處理,登錄成功,跳轉(zhuǎn)到登錄成功頁面success.jsp,否則跳轉(zhuǎn)到登錄失敗頁面failure.jsp。

(二)實現(xiàn)步驟

1、創(chuàng)建Web項目

創(chuàng)建Java Enterprise項目,添加Web Application功能

設(shè)置項目名與保存位置

單擊【Finish】按鈕

在項目結(jié)構(gòu)窗口里修改Artifact名 - LoginDemo01

編輯服務器配置,重新部署項目

切換到【Server】選項卡

2、創(chuàng)建登錄頁面

登錄頁面 - login.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>用戶登錄</title>
    </head>
    <body>
        <h3 style="text-align: center">用戶登錄</h3>
        <form action="doLogin.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="password" name="password"/></td>
                </tr>
                <tr align="center">
                    <td colspan="2">
                        <input type="submit" value="登錄"/>
                        <input type="reset" value="重置"/>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

3、創(chuàng)建登錄處理頁面

登錄處理頁面 - doLogin.jsp

<%
    // 獲取登錄表單數(shù)據(jù)
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    // 判斷登錄是否成功
    if (username.equals("無心劍") && password.equals("903213")) {
        // 跳轉(zhuǎn)到登錄成功頁面,傳遞用戶名
        response.sendRedirect("success.jsp?username=" + username);
    } else {
        // 跳轉(zhuǎn)到登錄失敗頁面,傳遞用戶名
        response.sendRedirect("failure.jsp?username=" + username);
    }
%>

4、創(chuàng)建登錄成功頁面

登錄成功頁面 - success.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>登錄成功</title>
    </head>
    <body>
        <h3 style="text-align: center">恭喜,<%=request.getParameter("username")%>,登錄成功!</h3>
    </body>
</html>

5、創(chuàng)建登錄失敗頁面

登錄失敗頁面 - failure.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>登錄失敗</title>
    </head>
    <body>
        <h3 style="text-align: center">遺憾,<%=request.getParameter("username")%>,登錄失?。?lt;/h3>
    </body>
</html>

6、編輯項目首頁

項目首頁 - index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>首頁</title>
    </head>
    <body>
        <h1 style="color: red; text-align: center">純JSP方式實現(xiàn)用戶登錄功能</h1>
        <h3 style="text-align: center"><a href="login.jsp" rel="external nofollow"  rel="external nofollow" >跳轉(zhuǎn)到登錄頁面</a></h3>
    </body>
</html>

(三)測試結(jié)果

啟動服務器,顯示首頁

單擊【跳轉(zhuǎn)到登錄頁面】超鏈接

輸入正確的用戶名和密碼(無心劍:903213)

單擊【登錄】按鈕,跳轉(zhuǎn)到登錄成功頁面

返回登錄頁面,輸入錯誤的用戶名或密碼

單擊【登錄】按鈕,跳轉(zhuǎn)到登錄失敗頁面

操作錄屏

二、JSP+Servlet方式實現(xiàn)用戶登錄功能

(一)實現(xiàn)思路

登錄頁面login.jsp,輸入用戶名和密碼后,跳轉(zhuǎn)到登錄處理程序LoginServlet進行業(yè)務邏輯處理,登錄成功,跳轉(zhuǎn)到登錄成功頁面success.jsp,否則跳轉(zhuǎn)到登錄失敗頁面failure.jsp

(二)實現(xiàn)步驟

1、創(chuàng)建Web項目

創(chuàng)建Java Enterprise項目,添加Web Application功能

設(shè)置項目名與保存位置

單擊【Finish】按鈕

在項目結(jié)構(gòu)窗口里修改Artifact名 - LoginDemo02

編輯服務器配置,重新部署項目

切換到【Server】選項卡

2、創(chuàng)建登錄頁面

登錄頁面 - login.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>用戶登錄</title>
    </head>
    <body>
        <h3 style="text-align: center">用戶登錄</h3>
        <form action="login" 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="password" name="password"/></td>
                </tr>
                <tr align="center">
                    <td colspan="2">
                        <input type="submit" value="登錄"/>
                        <input type="reset" value="重置"/>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

3、創(chuàng)建登錄處理程序

創(chuàng)建net.huawei.serlvet包,在包里創(chuàng)建LoginServlet

package net.huawei.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * 功能:登錄處理程序
 * 作者:華衛(wèi)
 * 日期:2023年05月03日
 */
@WebServlet(name = "LoginServlet", urlPatterns = "/login")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 設(shè)置請求對象字符編碼格式
        request.setCharacterEncoding("utf-8");
        // 獲取登錄表單數(shù)據(jù)
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        // 判斷登錄是否成功
        if (username.equals("無心劍") && password.equals("903213")) {
            // 采用重定向,跳轉(zhuǎn)到登錄成功頁面
            response.sendRedirect("success.jsp?username=" + URLEncoder.encode(username, "utf-8"));
        } else {
            // 采用重定向,跳轉(zhuǎn)到登錄失敗頁面
            response.sendRedirect("failure.jsp?username=" + URLEncoder.encode(username, "utf-8"));
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }
}

說明:必須設(shè)置請求對象的字符編碼為utf-8,否則輸入正確用戶名和密碼也會登錄失敗。重定向傳遞用戶名參數(shù)時,必須采用URLEncoder類的encode方法進行編碼,否則程序運行會報錯。

對應關(guān)系圖

4、創(chuàng)建登錄成功頁面

登錄成功頁面 - success.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>登錄成功</title>
    </head>
    <body>
        <h3 style="text-align: center">恭喜,<%=request.getParameter("username")%>,登錄成功!</h3>
    </body>
</html>

5、創(chuàng)建登錄失敗頁面

登錄失敗頁面 - failure.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>登錄失敗</title>
    </head>
    <body>
        <h3 style="text-align: center">遺憾,<%=request.getParameter("username")%>,登錄失??!</h3>
    </body>
</html>

6、編輯項目首頁

項目首頁 - index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>首頁</title>
    </head>
    <body>
        <h1 style="color: red; text-align: center">JSP+Servlet方式實現(xiàn)用戶登錄功能</h1>
        <h3 style="text-align: center"><a href="login.jsp" rel="external nofollow"  rel="external nofollow" >跳轉(zhuǎn)到登錄頁面</a></h3>
    </body>
</html>

(三)測試結(jié)果

啟動服務器,顯示首頁

單擊【跳轉(zhuǎn)到登錄頁面】超鏈接

輸入正確的用戶名和密碼(無心劍:903213)

單擊【登錄】按鈕,跳轉(zhuǎn)到登錄成功頁面

返回登錄頁面,輸入錯誤的用戶名或密碼

單擊【登錄】按鈕,跳轉(zhuǎn)到登錄失敗頁面

操作錄屏

三、JSP+Servlet+DB方式實現(xiàn)用戶登錄功能

(一)實現(xiàn)思路

總體上采用MVC架構(gòu)。登錄頁面login.jsp,輸入用戶名和密碼后,跳轉(zhuǎn)到登錄處理程序LoginServlet進行業(yè)務邏輯處理,調(diào)用服務層,服務層調(diào)用數(shù)據(jù)訪問層(DAO),連接數(shù)據(jù)庫,查詢數(shù)據(jù)庫,以此判斷是否登錄成功。登錄成功,跳轉(zhuǎn)到登錄成功頁面success.jsp,否則跳轉(zhuǎn)到登錄失敗頁面failure.jsp

MVC 是 Model、View 和 Controller 的縮寫,分別代表 Web 應用程序中的 3 種職責。

(二)實現(xiàn)步驟

1、創(chuàng)建數(shù)據(jù)庫

創(chuàng)建數(shù)據(jù)庫 - test

單擊【確定】按鈕

2、創(chuàng)建用戶表

創(chuàng)建用戶表結(jié)構(gòu) - t_user

CREATE TABLE `t_user`  (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用戶ID',
  `username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '用戶名',
  `password` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '用戶密碼',
  `telephone` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '聯(lián)系電話',
  `register_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '注冊時間',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

插入用戶記錄

INSERT INTO `t_user` VALUES (1, '無心劍', '12345', '15888781123', '2023-01-06 07:20:46');
INSERT INTO `t_user` VALUES (2, '陳燕文', '11111', '13990901140', '2023-02-06 11:40:49');
INSERT INTO `t_user` VALUES (3, '鄭素平', '22222', '15845678907', '2023-05-01 08:30:53');

3、創(chuàng)建Web項目

創(chuàng)建Java Enterprise項目,添加Web Application功能

設(shè)置項目名與保存位置

單擊【Finish】按鈕

在項目結(jié)構(gòu)窗口里修改Artifact名 - LoginDemo03

編輯服務器配置,重新部署項目

切換到【Server】選項卡

4、創(chuàng)建用戶實體類

創(chuàng)建net.huawei.bean包,然后在包里創(chuàng)建User類,跟用戶表(t_user)對應,簡稱ORM(Object Relation Mapping)

package net.huawei.bean;

import java.util.Date;

/**
 * 功能:用戶實體類
 * 作者:華衛(wèi)
 * 日期:2023年05月19日
 */
public class User {
    private int id;
    private String username;
    private String password;
    private String telephone;
    private Date registerTime;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public Date getRegisterTime() {
        return registerTime;
    }

    public void setRegisterTime(Date registerTime) {
        this.registerTime = registerTime;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", telephone='" + telephone + '\'' +
                ", registerTime=" + registerTime +
                '}';
    }
}

5、添加數(shù)據(jù)庫驅(qū)動程序

WEB-INF目錄下創(chuàng)建lib目錄,添加數(shù)據(jù)庫驅(qū)動程序

將數(shù)據(jù)庫驅(qū)動程序(jar包)作為庫添加到項目

單擊【Add as Library…】

單擊【OK】按鈕

6、創(chuàng)建數(shù)據(jù)庫連接管理工具類

創(chuàng)建net.huawei.dbutils包,在包里創(chuàng)建ConnectionManager

package net.huawei.dbutils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 功能:數(shù)據(jù)庫連接管理類
 * 作者:華衛(wèi)
 * 日期:2023年05月19日
 */
public class ConnectionManager {
    private static final String DRIVER = "com.mysql.jdbc.Driver"; // 數(shù)據(jù)庫驅(qū)動程序
    private static final String URL = "jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf8"; // 數(shù)據(jù)庫統(tǒng)一資源標識符
    private static final String USER = "root"; // 數(shù)據(jù)庫用戶
    private static final String PASSWORD = "903213"; // 數(shù)據(jù)庫密碼(記住改成自己的數(shù)據(jù)庫密碼)

    // 私有化構(gòu)造方法,拒絕實例化
    private ConnectionManager() {
    }

    // 獲取數(shù)據(jù)庫連接靜態(tài)方法
    public static Connection getConnection() {
        // 定義數(shù)據(jù)庫連接
        Connection conn = null;

        try {
            // 安裝數(shù)據(jù)庫驅(qū)動程序
            Class.forName(DRIVER);
            // 獲取數(shù)據(jù)庫連接
            conn = DriverManager.getConnection(URL, USER, PASSWORD);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        // 返回數(shù)據(jù)庫連接
        return conn;
    }

    // 關(guān)閉數(shù)據(jù)連接靜態(tài)方法
    public static void closeConnection(Connection conn) {
        // 判斷數(shù)據(jù)庫連接是否非空
        if (conn != null) {
            try {
                // 判斷連接是否未關(guān)閉
                if (!conn.isClosed()) {
                    // 關(guān)閉數(shù)據(jù)庫連接
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        // 獲取數(shù)據(jù)庫連接
        Connection conn = getConnection();
        // 判斷數(shù)據(jù)庫連接是否成功
        if (conn != null) {
            System.out.println("恭喜,數(shù)據(jù)庫連接成功~");
        } else {
            System.out.println("遺憾,數(shù)據(jù)庫連接失敗~");
        }
        // 關(guān)閉數(shù)據(jù)庫連接
        closeConnection(conn);
        System.out.println("數(shù)據(jù)庫連接已經(jīng)關(guān)閉~");
    }
}

運行程序,查看結(jié)果

7、創(chuàng)建用戶數(shù)據(jù)訪問類

net.huawei根包里創(chuàng)建dao子包,然后在子包里創(chuàng)建UserDao

package net.huawei.dao;

import net.huawei.bean.User;
import net.huawei.dbutils.ConnectionManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 功能:用戶數(shù)據(jù)訪問類
 * 作者:華衛(wèi)
 * 日期:2023年05月19日
 */
public class UserDao {
    /**
     * 用戶登錄方法
     * @param username
     * @param password
     * @return 用戶對象(非空:登錄成功,否則登錄失敗)
     */
    public User login(String username, String password) {
        // 聲明用戶對象
        User user = null;

        // 獲取數(shù)據(jù)庫連接
        Connection conn = ConnectionManager.getConnection();
        try {
            // 定義SQL字符串
            String strSQL = "SELECT * FROM t_user WHERE username = ? AND password = ?";
            // 創(chuàng)建預備語句對象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            // 設(shè)置占位符
            pstmt.setString(1, username);
            pstmt.setString(2, password);
            // 執(zhí)行查詢,返回結(jié)果集
            ResultSet rs = pstmt.executeQuery();
            // 判斷結(jié)果集是否為空
            if (rs.next()) {
                // 創(chuàng)建用戶對象
                user = new User();
                // 利用當前記錄字段值來設(shè)置用戶對象屬性
                user.setId(rs.getInt("id"));
                user.setUsername(rs.getString("username"));
                user.setPassword(rs.getString("password"));
                user.setTelephone(rs.getString("telephone"));
                user.setRegisterTime(rs.getTimestamp("register_time"));
            }
        } catch (SQLException e) {
            System.err.println(e.getMessage());
        } finally {
            // 關(guān)閉數(shù)據(jù)庫連接
            ConnectionManager.closeConnection(conn);
        }

        // 返回用戶對象
        return user;
    }
}

8、測試用戶數(shù)據(jù)訪問類

net.huawei根包里創(chuàng)建test子包,在子包里創(chuàng)建TestUserDao

package net.huawei.test;

import net.huawei.bean.User;
import net.huawei.dao.UserDao;
import org.junit.Test;

/**
 * 功能:測試用戶數(shù)據(jù)訪問類
 * 作者:華衛(wèi)
 * 日期:2023年05月19日
 */
public class TestUserDao {
    @Test
    public void testLogin() {
        String username = "無心劍";
        String password = "12345";

        // 創(chuàng)建用戶數(shù)據(jù)訪問對象
        UserDao userDao = new UserDao();
        // 調(diào)用登錄方法,返回用戶對象
        User user = userDao.login(username, password);
        // 判斷用戶登錄是否成功
        if (user != null) { // 成功
            System.out.println("恭喜,用戶[" + username + "]登錄成功~");
        } else { // 失敗
            System.out.println("遺憾,用戶[" + username + "]登錄失敗~");
        }
    }
}

運行程序,查看結(jié)果

修改用戶名和密碼,再次運行程序,提示登錄失敗

9、創(chuàng)建用戶服務類

net.huawei根包里創(chuàng)建service子包,在子包里創(chuàng)建UserService

package net.huawei.service;

import net.huawei.bean.User;
import net.huawei.dao.UserDao;

/**
 * 功能:用戶服務類
 * 作者:華衛(wèi)
 * 日期:2023年05月26日
 */
public class UserService {
    private UserDao userDao = new UserDao();
    
    public User login(String username, String password) {
        return userDao.login(username, password);
    }
}

10、創(chuàng)建登錄處理程序

net.huawei根包里創(chuàng)建servlet子包,在子包里創(chuàng)建LoginServlet

package net.huawei.servlet;

import net.huawei.bean.User;
import net.huawei.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * 功能:登錄處理程序
 * 作者:華衛(wèi)
 * 日期:2023年05月26日
 */
@WebServlet(name = "LoginServlet", urlPatterns = "/login")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 設(shè)置請求對象字符編碼格式
        request.setCharacterEncoding("utf-8");
        // 獲取登錄表單數(shù)據(jù)
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        // 創(chuàng)建用戶服務對象
        UserService us = new UserService();
        // 調(diào)用登錄方法,返回用戶對象
        User user = us.login(username, password);
        // 判斷登錄是否成功
        if (user != null) {
            // 采用重定向,跳轉(zhuǎn)到登錄成功頁面
            response.sendRedirect("success.jsp?username=" + URLEncoder.encode(username, "utf-8"));
        } else {
            // 采用重定向,跳轉(zhuǎn)到登錄失敗頁面
            response.sendRedirect("failure.jsp?username=" + URLEncoder.encode(username, "utf-8"));
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }
}

11、創(chuàng)建登錄頁面

登錄頁面 - login.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>用戶登錄</title>
    </head>
    <body>
        <h3 style="text-align: center">用戶登錄</h3>
        <form action="login" 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="password" name="password"/></td>
                </tr>
                <tr align="center">
                    <td colspan="2">
                        <input type="submit" value="登錄"/>
                        <input type="reset" value="重置"/>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

12、創(chuàng)建登錄成功頁面

登錄成功頁面 - success.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>登錄成功</title>
    </head>
    <body>
        <h3 style="text-align: center">恭喜,<%=request.getParameter("username")%>,登錄成功!</h3>
    </body>
</html>

13、創(chuàng)建登錄失敗頁面

登錄失敗頁面 - failure.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>登錄失敗</title>
    </head>
    <body>
        <h3 style="text-align: center">遺憾,<%=request.getParameter("username")%>,登錄失?。?lt;/h3>
    </body>
</html>

14、編輯項目首頁

項目首頁 - index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>首頁</title>
    </head>
    <body>
        <h1 style="color: red; text-align: center">JSP+Servlet+DB方式實現(xiàn)用戶登錄功能</h1>
        <h3 style="text-align: center"><a href="login.jsp">跳轉(zhuǎn)到登錄頁面</a></h3>
    </body>
</html>

(三)測試結(jié)果

啟動服務器,顯示首頁

單擊【跳轉(zhuǎn)到登錄頁面】超鏈接

輸入正確的用戶名和密碼(無心劍:12345)

單擊【登錄】按鈕,跳轉(zhuǎn)到登錄成功頁面

返回登錄頁面,輸入用戶名和密碼(陳燕文:12345)

單擊【登錄】按鈕,跳轉(zhuǎn)到登錄失敗頁面

登錄操作錄屏演示

四、課后作業(yè)

任務1、采用MVC模式實現(xiàn)用戶注冊功能

創(chuàng)建Web項目 - register

首頁

注冊頁面

注冊成功頁面

注冊失敗頁面

注冊操作錄屏演示

在Navicat里查看用戶表,看是否添加了新用戶記錄

任務2、在登錄成功頁面顯示用戶列表

測試UserDao的findAll()方法

總結(jié) 

到此這篇關(guān)于Java Web應用小案例之實現(xiàn)用戶登錄功能的文章就介紹到這了,更多相關(guān)Java Web實現(xiàn)用戶登錄功能內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • SpringBoot+Caffeine+Redis實現(xiàn)多級緩存的方法

    SpringBoot+Caffeine+Redis實現(xiàn)多級緩存的方法

    多級緩存是指在系統(tǒng)中部署多層功能互補的緩存組件,讓請求按照預設(shè)順序依次訪問各層緩存,僅當所有緩存層均未命中時,才訪問底層數(shù)據(jù)庫的架構(gòu)模式,這篇文章主要介紹了SpringBoot+Caffeine+Redis實現(xiàn)多級緩存的方法,需要的朋友可以參考下
    2026-02-02
  • Java實現(xiàn)兩人五子棋游戲(五) 判斷是否有一方勝出

    Java實現(xiàn)兩人五子棋游戲(五) 判斷是否有一方勝出

    這篇文章主要為大家詳細介紹了Java實現(xiàn)兩人五子棋游戲,判斷是否有一方勝出,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Java堆轉(zhuǎn)儲文件之1.6G大文件處理完整指南

    Java堆轉(zhuǎn)儲文件之1.6G大文件處理完整指南

    堆轉(zhuǎn)儲文件是優(yōu)化、分析內(nèi)存消耗的重要工具,這篇文章主要介紹了Java堆轉(zhuǎn)儲文件之1.6G大文件處理的相關(guān)資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2025-07-07
  • Java?-jar參數(shù)設(shè)置小結(jié)

    Java?-jar參數(shù)設(shè)置小結(jié)

    本文主要介紹了Java?-jar參數(shù)設(shè)置小結(jié),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-06-06
  • Springboot常用方法參數(shù)注解示例詳解

    Springboot常用方法參數(shù)注解示例詳解

    這篇文章主要介紹了Springboot常用方法參數(shù)注解及示例,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-08-08
  • Jmeter自定義函數(shù)base64加密實現(xiàn)過程解析

    Jmeter自定義函數(shù)base64加密實現(xiàn)過程解析

    這篇文章主要介紹了Jmeter自定義函數(shù)base64加密實現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-07-07
  • 關(guān)于java中可變長參數(shù)的定義及使用方法詳解

    關(guān)于java中可變長參數(shù)的定義及使用方法詳解

    下面小編就為大家?guī)硪黄P(guān)于java中可變長參數(shù)的定義及使用方法詳解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12
  • java如何讀取properties文件將參數(shù)值配置到靜態(tài)變量

    java如何讀取properties文件將參數(shù)值配置到靜態(tài)變量

    這篇文章主要介紹了java如何讀取properties文件將參數(shù)值配置到靜態(tài)變量問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • 淺談springboot之JoinPoint的getSignature方法

    淺談springboot之JoinPoint的getSignature方法

    這篇文章主要介紹了springboot之JoinPoint的getSignature方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • 解決JAVA8 Collectors.toMap value為null報錯的問題

    解決JAVA8 Collectors.toMap value為null報錯的問題

    這篇文章主要介紹了解決JAVA8 Collectors.toMap value為null報錯的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01

最新評論

龙门县| 蚌埠市| 怀远县| 武山县| 五原县| 西乡县| 田林县| 达尔| 望谟县| 莲花县| 江北区| 突泉县| 建湖县| 余江县| 齐河县| 天长市| 新源县| 乐平市| 东至县| 东丽区| 巨野县| 贡山| 罗源县| 宁陕县| 淮安市| 怀远县| 偃师市| 昌邑市| 图片| 榆树市| 平湖市| 抚州市| 庆安县| 东乌珠穆沁旗| 筠连县| 韶山市| 长宁县| 天长市| 若羌县| 长岛县| 虞城县|