Java+JSP+Mysql+Tomcat实现Web用户信息管理系统

Posted 水坚石青

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java+JSP+Mysql+Tomcat实现Web用户信息管理系统相关的知识,希望对你有一定的参考价值。

一、系统介绍

1.软件环境

Java:jdk1.8
mysql:8.0.13
Tomcat:8.5.23

2.系统功能

1.管理员登录系统
2.增加用户信息
3.修改用户信息
3.删除用户信息
4.查询用户信息

3.数据库

/*
 Navicat Premium Data Transfer

 Source Server         : MySQL
 Source Server Type    : MySQL
 Source Server Version : 80013
 Source Host           : localhost:3306
 Source Schema         : jsp_user_management

 Target Server Type    : MySQL
 Target Server Version : 80013
 File Encoding         : 65001

 Date: 21/06/2021 22:55:29
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for admin
-- ----------------------------
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin`  (
  `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of admin
-- ----------------------------
INSERT INTO `admin` VALUES ('admin', 'admin');

-- ----------------------------
-- Table structure for userinfo
-- ----------------------------
DROP TABLE IF EXISTS `userinfo`;
CREATE TABLE `userinfo`  (
  `userId` int(11) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
  `userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `userPwd` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `userAge` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `userPN` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `userJianjie` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `userNum` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `userPhone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `userTime` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`userId`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of userinfo
-- ----------------------------
INSERT INTO `userinfo` VALUES (00000011111, '张三', '111', '26', '第一监狱', '犯人', '0101', '12345678911', '2020-06-01');
INSERT INTO `userinfo` VALUES (00000011112, '张大', '222', '48', '第三监狱', '家属', '0102', '12345678911', '2021-06-01');
INSERT INTO `userinfo` VALUES (00000011113, '李四', '333', '35', '第二监狱', '犯人', '0201', '12345678911', '2021-06-01');

SET FOREIGN_KEY_CHECKS = 1;


二、系统展示

1.登录系统

在这里插入图片描述

2.主页面

在这里插入图片描述

3.新增用户信息

在这里插入图片描述

4.修改用户信息

在这里插入图片描述

5.查询用户信息

在这里插入图片描述

三、部分代码

DBUtil

package com.sjsq.vo;

/**
 * 管理员类
 * @author shuijianshiqing
 * @date 2021/4/29 22:11
 */
public class Admin {

    // 账号
    private String username;
    // 密码
    private String password;

    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;
    }

    @Override
    public String toString() {
        return "Admin{" +
                "username='" + username + '\\'' +
                ", password='" + password + '\\'' +
                '}';
    }
}

Admin

package com.sjsq.vo;

/**
 * 管理员类
 * @author shuijianshiqing
 * @date 2021/4/29 22:11
 */
public class Admin {

    // 账号
    private String username;
    // 密码
    private String password;

    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;
    }

    @Override
    public String toString() {
        return "Admin{" +
                "username='" + username + '\\'' +
                ", password='" + password + '\\'' +
                '}';
    }
}

AdminDaoImpl

package com.sjsq.dao.impl;

import com.sjsq.dao.AdminDao;
import com.sjsq.utils.DBUtil;
import com.sjsq.vo.Admin;

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

/**
 * @author shuijianshiqing
 * @date 2021/5/1 9:49
 */
public class AdminDaoImpl implements AdminDao {

    /**
     * 用户登录
     * @param admin
     * @return
     */
    @Override
    public Admin login(Admin admin) {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            // 1.获取数据库连接
            con = DBUtil.getConnection();
            // 2.写sql
            String sql = "select * from admin where username = ? and password = ?";
            // 3.预编译
            ps = con.prepareStatement(sql);
            // 4.设置值
            ps.setObject(1,admin.getUsername());
            ps.setObject(2,admin.getPassword());
            rs = ps.executeQuery();
            Admin adminLogin = null;
            if(rs.next()){
                adminLogin = new Admin();
                // 从数据库中获取值到实体类的setter方法中
                adminLogin.setUsername(rs.getString("username"));
                adminLogin.setPassword(rs.getString("password"));

                // 返回的是你查询出来的完整的对象
                return adminLogin;

            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            // 关闭资源,避免出现异常
            DBUtil.close(con,ps,rs);
        }
        return null;
    }
}

login.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
    <%
        // 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":"
                + request.getServerPort() + path + "/";
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <base href="<%=basePath %>" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户登录</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        h4{
            text-align: center;color: red;
        }
        body{
            background-color: powderblue;
        }
        a{
            text-decoration: none;font-size: 20px;color: black;
        }
        a:hover{
            text-decoration: underline;font-size: 24px;color: red;
        }
    </style>
</head>
<body>
    <form action="check-login.jsp" method="post">
        <h1>用户登录</h1>
        <hr/>
        <table align="center">
            <tr>
                <td>账号:</td>
                <td><input type="text" name="username" placeholder="请输入您的账号" autofocus="autofocus"></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="password" placeholder="请输入您的密码"></td>
            </tr>
            <tr>
                <td colspan="1">
                </td>
                <td>
                    <input type="submit" value="登录"/>
                    <input type="reset" value="重置"/>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

fail.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>登录失败</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        h4{
            text-align: center;color: red;
        }
        body{
            background-color: antiquewhite;
        }
        div{
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>用户登录</h1>
    <hr/>
    <h4>登录失败</h4>
    <div>
        <a href="login.jsp">返回登录</a>
    </div>
</body>
</html>

error.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>操作失败</title>
    <style type="text/css">
        body{
            text-align: center;
        }
        h1{

        }
        #before{
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>操作失败</h1>
    操作出错,请回到上一个页面!
    <div id="before">
        <a href="javascript: window.history.go(-1)">返回上一级</a>
    </div>
    </br>
</body>
</html>

add-user.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>新增用户</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        body{
            background-color: powderblue;
        }
        div{
            text-align: center;
        }
        #before{
            text-align: center;
        }
    </style>
</head>
<body>
    <%-- 头部 --%>
    <jsp:include page="top.jsp"/>

    <h1>新增用户</h1>
    <hr/>

    <div id="before">
        <a href="javascript: window.history.go(-1)">返回上一级</a>
    </div>
    </br>

    <form action="do-add-user.jsp" method="post" name="addForm">


        <div>
            <tr>
                <label>用户编号:</label>
                <input type="text" name="userId" id="userId" placeholder="用户编号" autofocus="autofocus">
            2-22-实现jsp通过tomcat连接mysql

IDEA+Java+JSP+Mysql+Tomcat实现Web商品信息管理系统

IDEA+Java+JSP+Mysql+Tomcat实现Web学生成绩管理系统

IDEA+Java+JSP+Mysql+Tomcat实现Web宠物信息管理系统

Java+JSP+Mysql+Tomcat实现Web用户信息管理系统

IDEA+Java+JSP+Mysql+Tomcat实现Web学生信息管理系统