JavaWeb-连接数据库实现用户登录、注册、修改密码(全代码)

news2024/11/17 3:26:53

上一篇博客中我通过使用HttpServlet完成一个假登录,这篇博客我将通过JDBC连接数据库,使其实现简单的用户登录、注册以及更改密码

一、MySQL:

MySQL部分代码:

-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users`  (
  `uid` int NOT NULL AUTO_INCREMENT,
  `username` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `pwd` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `email` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `sex` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  PRIMARY KEY (`uid`) USING BTREE,
  UNIQUE INDEX `username`(`username` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1017 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES (1002, '张三', '15915963', '22782@qq.com', '男');
INSERT INTO `users` VALUES (1003, '李四', '123000', '69307@qq.com', '男');
INSERT INTO `users` VALUES (1004, '马冬梅', '123456', 'madongmei@163.com', '女');

二、Java

项目结构:

bean/User存放用户的实体类,实现了序列化接口,定义私有属性,set,get方法的普通java类
dao/impl/UserDao 接口,声明所需要的所有方法
dao/impl/UserDaoImpl 用在和数据直接交互,比如常用的是定义交互数据库的类或接口
servlet/Enroll 继承HttpServlet类,重写doGet方法和doPost方法,接收注册信息
servlet/Forget 更改密码
servlet/Login 登录
util/JDBCUtil 连接数据库
util/RegexUtil 判断邮箱格式

bean/

User代码:

package com.bing.bean;

public class User {
    private Integer uid;
    private String username;
    private String password;
    private String email;
    private String sex;

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    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 getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "User{" +
                "uid=" + uid +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", email='" + email + '\'' +
                ", sex='" + sex + '\'' +
                '}';
    }
}

dao/

UserDao代码:

package com.bing.dao;

import com.bing.bean.User;

public interface UserDao {
    /**
     * 登录
     *
     * @param username 用户名
     * @param password 密码
     * @return User
     */
    User login(String username, String password);

    /**
     * 根据用户名判断数据库里用户是否存在
     *
     * @param username 用户名
     * @return true:用户存在  false:用户不存在
     */
    boolean userExists(String username);

    /**
     * 判断是否注册成功
     *
     * @param user  用户名
     * @param pwd   密码
     * @param email 邮箱
     * @param sex   性别
     * @return true:注册失败  false:注册成功
     */
    boolean register(String user, String pwd, String email, String sex);

    /**
     * 根据数据库判断用户名和邮箱是否对应
     *
     * @param username 用户名
     * @param email    邮箱
     * @return true:用户名和邮箱对应  false:用户名和邮箱不对应
     */

    boolean userExists(String username, String email);

    /**
     * 判断是否更改成功
     *
     * @param user  用户名
     * @param pwd   密码
     * @param email 邮箱
     * @return true:修改成功  false:修改失败
     */
    boolean change(String user, String pwd, String email);

    /**
     * 用户存在,密码不存在,即邮箱与用户名不匹配
     *
     * @param user  用户名
     * @param email 邮箱
     * @return true:邮箱与用户名不匹配,   false:用户与密码匹配
     */
    boolean emailNotExists(String user, String email);

}

dao/

impl/

UserDaoImpl代码:
package com.bing.dao.impl;

import com.bing.bean.User;
import com.bing.dao.UserDao;
import com.bing.util.JDBCUtil;

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

public class UserDaoImpl implements UserDao {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    boolean bo = false;

    public UserDaoImpl() {
        con = JDBCUtil.getCon();
    }
    @Override
    public User login(String username, String password) {
        User login = null;
        if (con != null) {
            // 判断数据库是否连接成功
            System.out.println("数据库连接成功~");
            String sql = "select * from users where username = ? and pwd = ?";
            try {
                ps = con.prepareStatement(sql);
                ps.setString(1, username);
                ps.setString(2, password);
                rs = ps.executeQuery();
                // 解析结果集
                while (rs.next()) {
                    login = new User();
                    login.setUid(rs.getInt("uid"));
                    login.setUsername(rs.getString("username"));
                    login.setPassword(rs.getString("pwd"));
                    login.setEmail(rs.getString("email"));
                    login.setSex(rs.getString("sex"));
                }


            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                JDBCUtil.close(rs, ps, con);
            }

        } else {
            System.out.println("数据库连接失败!");
        }
        return login;
    }

    @Override
    public boolean userExists(String username) {
        if (con != null) {
            System.out.println("数据库连接成功~");
            String sql = "select * from users where username = ? ";
            try {
                ps = con.prepareStatement(sql);
                ps.setString(1, username);
                rs = ps.executeQuery();
                while (rs.next()) {
                    // 如果有数据,bo为true,结束循环
                    bo = true;
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                JDBCUtil.close(rs, ps, con);
            }
        } else {
            System.out.println("数据库连接失败!");
        }
        return bo;// 返回boolean值,判断是否有这个用户
    }

    @Override
    public boolean userExists(String username, String email) {
        if (con != null) {
            System.out.println("数据库连接成功~");
            String sql = "select * from users where username = ? and email = ?";
            try {
                ps = con.prepareStatement(sql);
                ps.setString(1, username);
                ps.setString(2, email);
                rs = ps.executeQuery();
                while (rs.next()) {
                    bo = true;
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                JDBCUtil.close(rs, ps, con);
            }
        } else {
            System.out.println("数据库连接失败!");
        }
        return bo;
    }

    @Override
    public boolean register(String user, String pwd, String email, String sex) {
        if (!userExists(user)) {
            if (con != null) {
                System.out.println("数据库连接成功~");
                String sql = "insert into users(username,pwd,email,sex) values(?,?,?,?) ";
                try {
                    ps = con.prepareStatement(sql);
                    ps.setString(1, user);
                    ps.setString(2, pwd);
                    ps.setString(3, email);
                    ps.setString(4, sex);
                    int affectedRows = ps.executeUpdate();// 受影响的行数赋值给affectedRows
                    if (affectedRows > 0) {
                        bo = true;// 大于0则有行数受影响 数据库发生了改变 数据添加成功
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    JDBCUtil.close(ps, con);
                }

            } else {
                System.out.println("数据库连接失败!");
            }
        }
        return bo;// 返回boolean值 判断数据是否添加成功
    }


    @Override
    public boolean change(String user, String pwd, String email) {
        if (userExists(user, email)) {
            con = JDBCUtil.getCon();
            if (con != null) {
                System.out.println("数据库连接成功~");
                String sql = "update users set pwd = ? where username = ?";
                try {
                    ps = con.prepareStatement(sql);
                    ps.setString(1, pwd);
                    ps.setString(2, user);
                    int affectedRows = ps.executeUpdate();
                    if (affectedRows > 0) {
                        bo = true;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    JDBCUtil.close(ps, con);
                }
            } else {
                System.out.println("数据库连接失败!");
            }
        }
        return bo;
    }

    @Override
    public boolean emailNotExists(String user, String email) {
        if (userExists(user) && !userExists(user, email)) {
            bo = true;
        }
        return bo;
    }
}

servlet/

Enroll代码:

package com.bing.servlet;

import com.bing.dao.EnrollDao;
import com.bing.dao.impl.UserDaoImpl;
import com.bing.util.RegexUtil;

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;

@WebServlet("/enroll")// 注解避免了集中管理造成的配置冗长问题
public class Enroll extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        String user = req.getParameter("userName");
        String pwd = req.getParameter("pwd");
        String email = req.getParameter("email");
        String sex = req.getParameter("sex");

        // 响应的编码
        resp.setCharacterEncoding("UTF-8");
        // 文本格式
        resp.setContentType("text/html;charset=UTF-8");
        UserDaoImpl userDao = new UserDaoImpl();
        boolean exists;// 数据库是否存在某个用户
        boolean register;// 数据是否添加成功
        boolean bo = RegexUtil.isValidEmail(email);// 判断邮箱格式
        if (bo) {// 邮箱格式正确 执行下面操作
            exists = userDao.userExists(user);
            register = userDao.register(user, pwd, email, sex);
            if (exists) {
                resp.sendRedirect("userExists.jsp");
            } else if (register) {
                resp.sendRedirect("index.jsp");
            } else {
                resp.sendRedirect("cao.jsp");
            }
        } else {
            resp.sendRedirect("illegalEmail.jsp");
        }

    }

}

Forget代码:

package com.bing.servlet;

import com.bing.dao.EnrollDao;
import com.bing.dao.ForgetDao;
import com.bing.dao.impl.UserDaoImpl;

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;

@WebServlet("/forget")
public class Forget extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String user = req.getParameter("userName");
        String pwd = req.getParameter("pwd");
        String email = req.getParameter("email");
        // 响应的编码
        resp.setCharacterEncoding("UTF-8");
        UserDaoImpl userDao = new UserDaoImpl();
        if (!userDao.userExists(user)) {
            resp.sendRedirect("userNotExists.jsp");// 用户不存在
        } else if (userDao.emailNotExists(user, email)) {
            resp.sendRedirect("error.jsp");// 用户存在,邮箱不对
        } else if (userDao.login(user, pwd) != null) {
            resp.sendRedirect("2b.jsp");// 更改成功
        } else if (userDao.change(user, pwd, email)) {
            resp.sendRedirect("changeSuccessful.jsp");// 更改成功
        } else {
            resp.sendRedirect("cao.jsp");// 特殊情况
        }

    }
}

Login代码:

package com.bing.servlet;

import com.bing.dao.EnrollDao;
import com.bing.dao.impl.UserDaoImpl;

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;

@WebServlet("/welcome")
public class Login extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        /*
         * 处理请求源发送过来的数据
         * */
        req.setCharacterEncoding("UTF-8");// 将编码改为UTF-8
        String user = req.getParameter("userName");// user接收上个页面的userName值
        String pwd = req.getParameter("pwd");// pwd接收上个页面的pwd值
        // 响应的编码
        resp.setCharacterEncoding("UTF-8");
        // 文本格式
        resp.setContentType("text/html;charset=UTF-8");
        UserDaoImpl userDao = new UserDaoImpl();

        if (userDao.userExists(user) && userDao.login(user, pwd) == null) {
            resp.sendRedirect("forget.jsp");// 用户存在 密码不对 进入更改密码、忘记密码界面
            System.out.println(userDao.login(user, pwd));
        } else if (userDao.login(user, pwd) != null) {
            resp.sendRedirect("welcome.jsp");// 账号、密码正确  进入欢迎界面
        } else if (!userDao.userExists(user)) {
            resp.sendRedirect("enroll.jsp");// 用户不存在 注册用户
        } else {
            resp.sendRedirect("cao.jsp");// 特殊情况
        }
    }

}

util/

JDBCUtil代码:

package com.bing.util;

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

public class JDBCUtil {
    private static String driver = "com.mysql.cj.jdbc.Driver";// 驱动包
    private static String url = "jdbc:mysql://localhost:3306/jwTest?useSSL=false&serverTimezone=UTC";// 数据库地址
    private static String username = "root";// 数据库账号
    private static String password = "root";// 数据库密码
    private static Connection con = null;

    public static Connection getCon() {
        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return con;
    }

    public static void close(ResultSet rs, PreparedStatement ps, Connection con) {
        try {
            if (rs != null) {
                rs.close();
                System.out.println("ResultSet已释放...");
            }
            if (ps != null) {
                ps.close();
                System.out.println("PreparedStatement已释放...");
            }
            if (con != null) {
                con.close();
                System.out.println("Connection已释放...");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void close(PreparedStatement ps, Connection con) {
        try {
            if (ps != null) {
                ps.close();
                System.out.println("PreparedStatement已释放...");
            }
            if (con != null) {
                con.close();
                System.out.println("Connection已释放...");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

RegexUtil代码:

package com.bing.util;

import java.util.regex.Pattern;

public class RegexUtil {
    /*
     * 判断邮箱是否合法
     * */
    public static boolean isValidEmail(String email) {
        // 正则表达式
        String regex = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
        // 编译正则表达式
        Pattern pattern = Pattern.compile(regex);
        // 匹配输入的邮箱地址
        return pattern.matcher(email).matches();
    }
}

三、jsp

2b.jsp代码:

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/17
  Time: 16:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<style>
    h1 {
        text-align: center;
        color: aqua;
    }

    div {
        width: 500px;
        height: 90px;
        text-align: center;
        margin: 50px auto;
    }

    button {
        width: 120px;
        height: 40px;
        border-radius: 5px;
        border: 0px;
        cursor: pointer;
    }

    #enroll:hover {
        background-color: coral;
    }
</style>
<body>
<h1>
    你的密码不就是这个?😤
</h1>
<div>
    <button value="去登录" id="enroll" onclick="window.location.href ='/myWebTest_war_exploded/index.jsp'">去登录
    </button>
</div>
</body>
</html>

cao.jsp代码:

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/16
  Time: 23:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<script>
    console.log("😤why")
</script>
<style>
  h1{
    color: red;
    text-align: center;
  }
</style>
<body>

<h1>😭😭😭😭😭😭😭😭😭😭</h1><br>
<h1>因不可控因素,操作失败!!!!!!</h1>
</body>
</html>

changeSuccessful.jsp代码:

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/16
  Time: 23:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>嘻嘻💕</title>
</head>
<style>
    h1 {
        text-align: center;
        color: crimson;
    }

    div {
        width: 500px;
        height: 90px;
        text-align: center;
        margin: 50px auto;
    }

    #enroll {
        margin-right: 30px;
    }
    button{
        width: 120px;
        height: 40px;
        border-radius: 5px;
        border: 0px;
        cursor: pointer;
    }
    #enroll:hover{
        background-color: coral;
    }
</style>
<body>
<h1>更改成功!</h1></br>
<div>
    <button value="去登录" id="enroll" onclick="window.location.href ='/myWebTest_war_exploded/index.jsp'">去登录</button>
</div>

</body>
</html>

enroll.jsp

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/14
  Time: 18:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
    <style>
        body {
            background-color: antiquewhite;
        }

        div {
            width: 370px;
            height: 400px;
            margin: auto auto;
            background-color: white;
            border-radius: 5px;
        }

        .t {
            width: 100%;
            height: 100%;
        }

        #head {
            font-family: FangSong;
            font-size: 32px;
            font-weight: bold;
            text-align: center;
            margin-bottom: 15px;
            margin-top: 15px;
        }

        .one {
            width: 360px;
            height: 45px;
        }

        .one p {
            font-family: SimHei;
            font-size: 17px;
            text-align: right;
        }

        .one input {
            width: 210px;
            height: 45px;
            outline: none;
            border: none;
            border-bottom: 1px solid #000
        }

        .two {
            width: 120px;
            height: 45px;
        }

        .three p {
            font-family: SimHei;
            font-size: 17px;
            text-align: right;
        }

        #enroll {
            width: 330px;
            height: 45px;
            border: none;
            background-color: #ed7158;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            font-family: "Microsoft YaHei UI";
        }

        .one input:hover {
            border-color: red;
        }

        #enroll:hover {
            background-color: #d54d32;
        }
    </style>

</head>

<body>
<div>
    <form action="enroll" method="post">
        <table class="t">
            <tr>
                <td colspan="2"><p id="head">注册账号</p></td>
            </tr>
            <tr class="one">
                <td class="two"><p>账&nbsp;&nbsp;&nbsp;&nbsp;号:</p></td>
                <%--
                placeholder:用于提供有关输入字段所需内容的提示或说明
                onketup:限制中文
                pattern:限制中文个数
                required:不能为空
                --%>
                <td><input type="text" name="userName" placeholder="仅支持中文(2-6位)"
                           onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')"
                           onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/u4E00-/u9FA5]/g,''))"
                           pattern="[\u4e00-\u9fa5]{2,6}" maxlength="6">
                </td>
            </tr>
            <tr class="one">
                <td class="two"><p>密&nbsp;&nbsp;&nbsp;&nbsp;码:</p></td>
                <td><input type="password" name="pwd" id="pwd" placeholder="密码(6-16位)" minlength="6" maxlength="16">
                </td>
            </tr>
            <tr class="one">
                <td class="two"><p>确认密码:</p></td>
                <td><input type="password" name="confirmPwd" id="confirmPwd" placeholder="请再次输入密码" minlength="6" maxlength="16">
                </td>
            </tr>
            <tr class="one">
                <td class="two"><p>电子邮箱:</p></td>
                <td><input type="email" name="email" placeholder="请输入电子邮箱"></td>
            </tr>
            <tr class="three">
                <td class="two"><p>性&nbsp;&nbsp;&nbsp;&nbsp;别:</p></td>
                <td>
                    <input type="radio" name="sex" value="男">男
                    <input type="radio" name="sex" value="女">女
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center">
                    <input type="submit" value="注册" id="enroll">
                </td>
            </tr>
        </table>
    </form>
</div>
<script>
    <!-- required 必须选择一个-->
    var inputs = document.getElementsByTagName('input');
    for (var i = 0; i < inputs.length; i++) {
        inputs[i].required = true;
    }
    const form = document.querySelector('form');
    const password1 = document.getElementById('pwd');
    const password2 = document.getElementById('confirmPwd');

    form.addEventListener('submit', function(event) {
        if (password1.value !== password2.value) {
            alert('两次密码不同!');
            event.preventDefault();
        }
    });
</script>
</body>
</html>

error.jsp

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/16
  Time: 23:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>嘻嘻💕</title>
</head>
<style>
    h1 {
        text-align: center;
        color: crimson;
    }

    div {
        width: 500px;
        height: 90px;
        text-align: center;
        margin: 50px auto;
    }
    button{
        width: 120px;
        height: 40px;
        border-radius: 5px;
        border: 0px;
        cursor: pointer;
    }
    #enroll:hover{
        background-color: coral;
    }
</style>
<body>
<h1>邮箱与用户名不匹配,请重新更改密码</h1></br>
<h1></h1>
<div>
    <button value="更改密码" id="enroll" onclick="window.location.href ='/myWebTest_war_exploded/forget.jsp'">更改密码</button>
</div>

</body>
</html>

forget.jsp

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/14
  Time: 20:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改密码</title>
    <style>
        body {
            background-color: antiquewhite;
        }

        div {
            width: 370px;
            height: 400px;
            margin: auto auto;
            background-color: white;
            border-radius: 5px;
        }

        .t {
            width: 100%;
            height: 100%;
        }

        #head {
            font-family: FangSong;
            font-size: 32px;
            font-weight: bold;
            text-align: center;
            margin-bottom: 15px;
            margin-top: 15px;
        }

        .one {
            width: 360px;
            height: 45px;
        }

        .one p {
            font-family: SimHei;
            font-size: 17px;
            text-align: right;
        }

        .one input {
            width: 210px;
            height: 45px;
            outline: none;
            border: none;
            border-bottom: 1px solid #000
        }

        .two {
            width: 120px;
            height: 45px;
        }


        #enroll {
            width: 330px;
            height: 45px;
            border: none;
            background-color: #ed7158;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            font-family: "Microsoft YaHei UI";
        }

        .one input:hover {
            border-color: red;
        }

        #enroll:hover {
            background-color: #d54d32;
        }
    </style>

</head>
<body>
<div>
    <form action="forget" method="post">
        <table class="t">
            <tr>
                <td colspan="2"><p id="head">修改密码</p></td>
            </tr>
            <tr class="one">
                <td class="two"><p>账&nbsp;&nbsp;&nbsp;&nbsp;号:</p></td>
                <td><input type="text" name="userName" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')"
                           onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/u4E00-/u9FA5]/g,''))"
                           pattern="[\u4e00-\u9fa5]{2,6}" maxlength="6"
                           placeholder="仅支持中文(2-6位)">
                </td>
            </tr>
            <tr class="one">
                <td class="two"><p>密&nbsp;&nbsp;&nbsp;&nbsp;码:</p></td>
                <td><input type="password" name="pwd" id = "pwd" placeholder="密码(6-16位)" minlength="6" maxlength="16">
                </td>
            </tr>
            <tr class="one">
                <td class="two"><p>确认密码:</p></td>
                <td><input type="password" name="confirmPwd" id = "confirmPwd" placeholder="请再次输入密码" minlength="6" maxlength="16">
                </td>
            </tr>
            <tr class="one">
                <td class="two"><p>电子邮箱:</p></td>
                <td><input type="email" name="email" placeholder="请输入电子邮箱"></td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center">
                    <input type="submit" value="更改" id="enroll">
                </td>
            </tr>
        </table>
    </form>
</div>
<script>
    <!-- required 必须选择一个-->
    var inputs = document.getElementsByTagName('input');
    for (var i = 0; i < inputs.length; i++) {
        inputs[i].required = true;
    }
    const form = document.querySelector('form');
    const password1 = document.getElementById('pwd');
    const password2 = document.getElementById('confirmPwd');

    form.addEventListener('submit', function(event) {
        if (password1.value !== password2.value) {
            alert('两次密码不同!');
            event.preventDefault();
        }
    });
</script>
</body>
</html>

illgalEmail.jsp

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/16
  Time: 23:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<style>
    h1 {
        color: red;
        text-align: center;
    }

    div {
        width: 500px;
        height: 90px;
        text-align: center;
        margin: 50px auto;
    }

    button {
        width: 120px;
        height: 40px;
        border-radius: 5px;
        border: 0px;
        cursor: pointer;
    }

    #enroll:hover {
        background-color: coral;
    }
</style>
<body>
<h1>你邮箱是这个?请输入正确的邮箱。3q🤗</h1></br>
<button value="重新注册" id="enroll" onclick="window.location.href ='/myWebTest_war_exploded/enroll.jsp'">重新注册
</button>
</body>
</html>

index.jsp

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/14
  Time: 16:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Ybb778</title>
</head>
<style>
    body {
        background-image: url("image/bkgd.jpg");
        background-size: 100% 100%;
    }

    p {
        font-family: FangSong;
        font-size: 40px;
        font-weight: bold;
        text-align: center;
        margin-top: 18px;
        margin-bottom: 10px;
    }

    .biao {
        width: 450px;
        height: 300px;
        margin: auto auto;
        background-color: white;
        border-radius: 5px;
    }

    tr {
        width: 400px;
        height: 40px;
        border: 0;
    }

    .one input {
        width: 400px;
        height: 35px;
        outline: none;
        border: none;
        border-bottom: 1px solid #000
    }

    .t {
        width: 100%;
        height: 100%;
    }

    .one {
        text-align: center;
    }

    #two {
        border: none;
        background-color: #ed7158;
        border-radius: 5px;
        font-size: 16px;
        font-family: "Microsoft YaHei UI";
        cursor: pointer;
    }

    .three {
        text-align: center;
    }

    .four {
        text-decoration: none;
        color: #696969;
    }

    .five {
        color: #C0C0C0;
    }

    .one input:hover {
        border-color: red;
    }

    .four:hover {
        color: #383030;
    }

    #two:hover {
        background-color: #d54d32;
    }
</style>

<body>
<div class="biao">
    <form action="welcome" method="post">
        <table class="t">
            <tr>
                <td><p>无聊</p></td>
            </tr>
            <tr>
                <td class="one"><input type="text" name="userName" placeholder="账号(中文)"
                                       onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')"
                                       onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/u4E00-/u9FA5]/g,''))"
                                       pattern="[\u4e00-\u9fa5]{2,6}" maxlength="6">
                </td>
            </tr>
            <tr>
                <td class="one"><input type="password" name="pwd" placeholder="密码(6-16位)" minlength="6"
                                       maxlength="16">
                </td>
            </tr>
            <tr>
                <td class="one"><input type="submit" value="登录" id="two"></td>
            </tr>
            <tr>
                <td class="three"><a href="enroll.jsp" class="four">注册账号</a><a class="five">丨</a><a
                        href="forget.jsp" class="four">忘记密码</a></td>
            </tr>
        </table>
    </form>
</div>
<script>
    <!-- required 必须选择一个-->
    var inputs = document.getElementsByTagName('input');
    for (var i = 0; i < inputs.length; i++) {
        inputs[i].required = true;
    }
</script>
</body>
</html>

userExists.jsp

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/16
  Time: 21:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>嘻嘻💕</title>
</head>
<style>
    h1 {
        text-align: center;
        color: crimson;
    }

    div {
        width: 500px;
        height: 90px;
        text-align: center;
        margin: 50px auto;
    }

    #enroll {
        margin-right: 30px;
    }
    button{
        width: 120px;
        height: 40px;
        border-radius: 5px;
        border: 0px;
        cursor: pointer;
    }
    #enroll:hover{
        background-color: coral;
    }
    #forget:hover{
        background-color: aquamarine;
    }
</style>
<body>
<h1>该用户已存在!</h1>
<div>
    <button value="重新注册" id="enroll" onclick="window.location.href ='/myWebTest_war_exploded/enroll.jsp'">重新注册</button>
    <button value="更改密码" id="forget" onclick="window.location.href ='/myWebTest_war_exploded/forget.jsp'">忘记密码</button>
</div>

</body>
</html>

userNotExists.jsp

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/16
  Time: 22:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>嘻嘻💕</title>
</head>
<style>
    h1 {
        text-align: center;
        color: crimson;
    }

    div {
        width: 500px;
        height: 90px;
        text-align: center;
        margin: 50px auto;
    }

    #enroll {
        margin-right: 30px;
    }
    button{
        width: 120px;
        height: 40px;
        border-radius: 5px;
        border: 0px;
        cursor: pointer;
    }
    #enroll:hover{
        background-color: coral;
    }
</style>
<body>
<h1>此用户不存在!</h1></br>
<h1></h1>
<div>
    <button value="重新注册" id="enroll" onclick="window.location.href ='/myWebTest_war_exploded/enroll.jsp'">去注册</button>
</div>

</body>
</html>

welcome.jsp

<%--
  Created by IntelliJ IDEA.
  User: xbyan
  Date: 2023/2/16
  Time: 12:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>welcome</title>
</head>
<style>
    h1{
        color: orange;
        text-align: center;
    }
</style>
<body>
<h1>欢迎你😊😍😘🥰🤗</h1>
</body>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/354736.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

WSL(ubuntu2204)使用xfce4桌面打不开语言支持及配置WSL服务自启

语言支持报错 在图形桌面或命令行打开语言支持报错&#xff1a;dbus.exceptions.DBusException: org.freedesktop.DBus.Error.FileNotFound: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory itboonelocalhost:/$ sudo /usr/bin/gnome-…

【SCL】1200案例:天塔之光数码管显示液体混合水塔水位

使用scl编写天塔之光&数码管显示&液体混合&水塔水位 文章目录 目录 文章目录 前言 一、案例1&#xff1a;天塔之光 1.控制要求 2.编写程序 3.效果 二、案例2&#xff1a;液体混合 1.控制要求 2.编写程序 三、案例3&#xff1a;数码管显示 1.控制要求 2.编写程序 3…

转载:项目分析信息方法论

转载一篇最近看到的项目分析信息法&#xff1a;如何快速分析项目和如何详细分析项目。 一、如何快速分析项目&#xff1f; 可以从6个点进行分析&#xff0c;分别是&#xff1a;「流量效率&#xff0c;销转效率&#xff0c;交付效率&#xff0c;客单价&#xff0c;毛利率&…

【程序化天空盒】过程记录02:云扰动 边缘光 消散效果

写在前面 写在前面唉&#xff0c;最近筋疲力竭&#xff0c;课题组的东西一堆没做&#xff0c;才刚刚开始带着思考准备练习作品&#xff0c;从去年5月份开始到现在真得学了快一年了&#xff0c;转行学其他的真的好累&#xff0c;&#xff0c;不过还是加油&#xff01; 下面是做…

zlib压缩原理

数据压缩的本质 去除数据中的冗余信息&#xff0c;对于ABABABABABABAB字样的字符串&#xff0c;AB出现了7次&#xff0c;占用14个字节&#xff0c;如果将该字符串编码为7AB&#xff0c;只占用3个字节。 为什么需要对数据压缩 数据需要存储或者传输&#xff0c;为了节省磁盘空…

ONNXRUNTUIME实例分割网络说明

ONNXRUNTUIME c使用&#xff08;分割网络&#xff09;与相关资料&#xff08;暂记&#xff09; initiate a env with an id name(使用id名称启动env) create session (创建会话 ) onnxenv -> sessioninputname [“x”] ,outputname [“t”]inputnodedim [[1,1,192,192…

Linux单一服务管理systemctl

基本上systemd这个启动服务机制只有systemctl命令来处理&#xff0c;所以全部的操作都需要使用systemctl systemctl管理单一服务 一般来说服务的启动有两个阶段&#xff0c;一个是开机是否启动&#xff0c;以及现在是否启动 systemctl【command】【unit】 command主要有&…

VS2017+OpenCV4.5.5 决策树-评估是否发放贷款

决策树是一种非参数的监督学习方法&#xff0c;主要用于分类和回归。 决策树结构 决策树在逻辑上以树的形式存在&#xff0c;包含根节点、内部结点和叶节点。 根节点&#xff1a;包含数据集中的所有数据的集合内部节点&#xff1a;每个内部节点为一个判断条件&#xff0c;并且…

mysql详解之innoDB

索引 Mysql由索引组织&#xff0c;所以索引是mysql多重要概念之一。 聚簇索引 InnoDB和MyISAm一样都是采用B树结构&#xff0c;但不同点在于InnoDB是聚簇索引&#xff08;或聚集索引&#xff09;&#xff0c;将数据行直接放在叶子节点后面。 这里可能存在一个误区&#xff1…

【C语言】编程初学者入门训练(14)

文章目录131. kiki学结构体和指针132. kiki定义电子日历类133. 圣诞树134. 超级圣诞树131. kiki学结构体和指针 问题描述&#xff1a;KiKi学习了结构体和指针&#xff0c;他了解了结构体类型可以定义包含多个不同类型成员&#xff0c;而指针本质是内存地址&#xff0c;是引用数…

【人脸检测】Yolov5Face:优秀的one-stage人脸检测算法

论文题目&#xff1a;《YOLO5Face: Why Reinventing a Face Detector》 论文地址&#xff1a;https://arxiv.org/pdf/2105.12931.pdf 代码地址&#xff1a;https://github.com/deepcam-cn/yolov5-face 1.简介 近年来&#xff0c;CNN在人脸检测方面已经得到广泛的应用。但是许多…

【C++的OpenCV】第一课-opencv的间接和安装(Linux环境下)

第一课-目录一、基本介绍1.1 官网1.2 git源码1.3 介绍二、OpenCV的相关部署工作2.1 Linux平台下部署OpenCV一、基本介绍 1.1 官网 opencv官网 注意&#xff1a;官网为英文版本&#xff0c;可以使用浏览器自带的翻译插件进行翻译&#xff0c;真心不推荐大家去看别人翻译的&am…

过滤器和监听器

1、过滤器Filter 作用是防止SQL注入、参数过滤、防止页面攻击、空参数矫正、Token校验、Session验证、点击率统计等等&#xff1b; 使用Filter的步骤 新建类&#xff0c;实现Filter抽象类&#xff1b;重写init、doFilter、destroy方法&#xff1b;在SpringBoot入口中添加注解…

演示Ansible中的角色使用方法(ansible roles)

文章目录一、ansible 角色简介二、roles目录结构三、role存放的路径&#xff1a;配置文件ansible.cfg中定义四、创建目录结构五、playbook中使用rolesplaybook变量会覆盖roles中的定义变量六、控制任务执行顺序七、ansible—galaxy命令工具八、安装选择的角色1.从网上下载&…

使用vue3,vite,less,flask,python从零开始学习硅谷外卖(41-82集)

第41集&#xff1a;这里遇到个大坑&#xff0c;因为这种项目有很多页面&#xff0c;有时候有的页面忘了保存就会出错&#xff0c;还很难排查&#xff0c;浪费了我快半天的时间。可以把vscode的代码自动保存打开&#xff0c;以后就不会踩坑了。 第42集&#xff1a;没啥好说的。 …

判断字符串中的字符的类型isdecimal();isalpha();isdigit();isalnum()

【小白从小学Python、C、Java】 【计算机等级考试500强双证书】 【Python-数据分析】 判断字符串中的字符的类型 isdecimal()&#xff1b;isalpha()&#xff1b;isdigit()&#xff1b;isalnum() [太阳]选择题 对于代码中isdecimal()和isalnum()输出的结果是? s "ABc123&…

亿级高并发电商项目-- 实战篇 --万达商城项目 十一(编写商品搜索功能、操作商品同步到ES、安装RabbitMQ与Erlang,配置监听队列与消息队列)

&#x1f44f;作者简介&#xff1a;大家好&#xff0c;我是小童&#xff0c;Java开发工程师&#xff0c;CSDN博客博主&#xff0c;Java领域新星创作者 &#x1f4d5;系列专栏&#xff1a;前端、Java、Java中间件大全、微信小程序、微信支付、若依框架、Spring全家桶 &#x1f4…

Sandboxie-沙箱软件-Plus版本(Qt)-主框架程序-SandMan.exe-创建语言文件-tr-Qt-语言国际化

文章目录1.功能介绍2.Qt语言国际化3.设置软件的语言版本4.作者答疑1.功能介绍 沙箱软件的增强版本采用Qt架构开发&#xff0c;核心模块与经典版本相同&#xff0c;本文主要介绍SandMan.exe这个主程序代码。在main.cpp这个入口函数里&#xff0c;有主窗口入口&#xff0c;如下所…

2.5|iot冯|方元-嵌入式linux系统开发入门|2.13+2.18

一、 Linux 指令操作题&#xff08;共5题&#xff08;共 20 分&#xff0c;每小题 4分&#xff09;与系统工作、系统状态、工作目录、文件、目录、打包压缩与搜索等主题相关。1.文件1.1文件属性1.2文件类型属性字段的第1个字符表示文件类型&#xff0c;后9个字符中&#xff0c;…

【物联网】智慧农业病虫害精准辨识竞赛思路及代码分享

来源&#xff1a;投稿 作者&#xff1a;LSC 编辑&#xff1a;学姐 比赛官网: https://www.dataglobal.cn/cmpt/signUpInfo200.html 任务描述 请参赛者设计智慧农业病虫害检测系统&#xff0c;给出一体化问题解决方案&#xff0c;鼓励参赛选手结合某一果园/农作物实际情况建立…