JavaWeb实现学生管理系统
Posted 小菜鸟想逆袭
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaWeb实现学生管理系统相关的知识,希望对你有一定的参考价值。
JavaWeb实现学生管理系统
- 一、项目介绍
- 二、项目结构
- 三、前期准备
- 四、代码实现
- 1.JSP界面实现
- 2.JavaBean实体类封装数据
- 3.三层架构
- (1)表示层servlet
- ① 用户登录表示层 (LoginServlet.java)
- ② 用户注册表示层 (RegisterServlet.java)
- ③ 分页查询表示层 (ShowStudentsByPageServlet.java)
- ④ 查询所学生信息表示层 (ShowAllStudentsServlet.java)
- ⑤ 添加学生表示层 (AddServlet.java)
- ⑥ 删除学生表示层 (DeleteServlet.java)
- ⑦ 根据学号查询学生信息表示层 (QueryStudentBySnoSevlet.java)
- ⑧ 修改学生信息表示层 (UpdateServlet.java)
- ⑨ 退出登录表示层 (QuitServlet.java)
- (2)业务逻辑层service
- (3)数据访问层dao
一、项目介绍
该项目是基于JavaWeb实现的学生管理系统,使用maven进行管理jar包,能够对学生信息进行增删改查,分页查询,以及实现管理员的注册、登录
数据库:mysql
开发工具:idea
开发环境:jdk 1.8 + tomcat
二、项目结构
三、前期准备
1.配置maven环境,在pom.xml配置文件中配置项目所依赖的jar包
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
2.在MySql数据库中,创建登录注册表login和学生信息表student
(1)登录注册表login
(2)学生信息表student
(3)创建数据表代码
SET NAMES utf-8;
CREATE DATABASE studentManager;
USE studentManager;
CREATE TABLE student
(
sno INT PRIMARY KEY,
sname VARCHAR(20) NOT NULL,
sex CHAR(4) ,
age INT DEFAULT 20,
phone VARCHAR(30)
);
INSERT INTO student VALUES(1001,'jack','男',23,'13389076524');
INSERT INTO student VALUES(1002,'rose','女',23,'18760987543');
INSERT INTO student VALUES(1003,'tom','男',23,'13389067823');
INSERT INTO student VALUES(1004,'王麻子','男',23,'13560738947');
INSERT INTO student VALUES(1005,'大麻子','男',23,'18899067532');
INSERT INTO student VALUES(1006,'小麻子','男',23,'15678634789');
INSERT INTO student VALUES(1007,'老麻子','男',23,'12199834572');
INSERT INTO student VALUES(1008,'张三','男',23,'15533098843');
INSERT INTO student VALUES(1009,'长萨珊','女',23,'12209835679');
INSERT INTO student VALUES(1010,'李四','女',23,'15509087635');
INSERT INTO student VALUES(1011,'王五','男',23,'15788679043');
INSERT INTO student VALUES(1012,'赵六','女',23,'12489034506');
INSERT INTO student VALUES(1013,'刘二','男',23,'13560596743');
CREATE TABLE login
(
uid INT PRIMARY KEY,
pwd VARCHAR(20) NOT NULL,
);
INSERT INTO login VALUES(1, '1234');
INSERT INTO login VALUES(2, '2222');
INSERT INTO login VALUES(3, '6688');
3.配置tocamt
四、代码实现
1.JSP界面实现
(1)首页-登录界面 (index.jsp)
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>学生信息管理平台</title>
<style>
.titleDiv
height: 85px;
color:white;
padding-top: 30px;
font-size: 50px;
padding-left: 30px;
font-family: 隶书;
.mainDiv
width: 899px;
height: 500px;
border: 4px rgb(237, 237, 237) solid;
border-radius: 5px;
background-image: url("输入你要的图片链接!");
margin: auto;
margin-top: 50px;
.loginDiv
height: 220px;
width: 260px;
padding:50px;
background-color:rgba(255,255,255,0.9);
border-radius:25px;
border:1px #bdbdbd solid;
opacity:0.9;
float: right;
margin-right: 100px
.name
font-size: 25px;
a
font-size:15px;
color:#59c2c5;
padding-left:20px;
.item
height:60px;
.item input
line-height:40px;
width:245px;
border:none;
border-bottom: 1px solid #59c2c5;
margin-bottom: 20px;
margin-top: 10px;
.login-btn
display:block;
width:255px;
height:50px;
color:#fff;
background:#59c2c5;
font-size:16px;
line-height:30px;
text-align:center;
border-radius:10px;
border:none;
margin-bottom: 20px;
margin-top: 10px;
</style>
</head>
<body>
<div class="mainDiv">
<div class="titleDiv">学生信息管理平台</div>
<form action="LoginServlet" method="post">
<div class="loginDiv">
<div class="name">
用户登录 <a href="register.jsp"> 立即注册</a>
</div>
<div class=item>
<input type="text" name="uid" placeholder="用户名"/>
</div>
<div class=item>
<input type="password" name="pwd" placeholder="密码"/>
</div>
<input type="submit" class="login-btn" value="登 录"/>
<%
if(session.getAttribute("loginErrorMessage") != null)
String loginErrorMessage = (String)session.getAttribute("loginErrorMessage");
out.print(loginErrorMessage);
%>
<%
String register = (String) request.getAttribute("register");
if (register!= null)
if (register.equals("reg"))
out.println("注册成功, 请登录!");
%>
</div>
</form>
</div>
</body>
</html>
(2)用户注册界面 (register.jsp)
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>注册账号</title>
<style>
.mainDiv
width: 899px;
height: 500px;
border: 4px rgb(237, 237, 237) solid;
border-radius: 5px;
background-image: url("输入你要的图片链接!");
margin: auto;
margin-top: 50px;
.titleDiv
height: 85px;
color:white;
padding-top: 30px;
font-size: 50px;
padding-left: 30px;
font-family: 隶书;
.registerDiv
height: 220px;
width: 260px;
padding:50px;
background-color:rgba(255,255,255,0.9);
border-radius:25px;
border:1px #bdbdbd solid;
opacity:0.9;
float: right;
margin-right: 100px
.name
font-size: 25px;
.item
height:60px;
.item input
line-height:40px;
width:245px;
border:none;
border-bottom: 1px solid #59c2c5;
margin-bottom: 20px;
margin-top: 10px;
.btn
display:block;
width:255px;
height:50px;
color:#fff;
background:#59c2c5;
font-size:16px;
line-height:30px;
text-align:center;
border-radius:10px;
border:none;
margin-top: 10px;
a
font-size:18px;
padding-left:200px;
padding-bottom: 50px;
color:#59c2c5;
</style>
</head>
</head>
<body>
<div class="mainDiv">
<div class="titleDiv">学生信息管理平台</div>
<form action = "RegisterServlet">
<div class = "registerDiv">
<div class = "name">用户注册</div>
<div class = "item">
<input type = "text" name = "uid" placeholder="账号"/>
</div>
<div class = "item">
<input type = "password" name = "pwd" placeholder="密码"/>
</div>
<input type = "submit" class = "btn" value = "注册"/>
<a href = "index.jsp" >返回</a>
</div>
</form>
</div>
</body>
</html>
(3)登录成功-主界面 (main.jsp)
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="com.stu.po.Student" %>
<!DOCTYPE html>
<html >
<head>
<title>学生信息管理平台</title>
<style>
.titleDiv
height: 85px;
color:white;
padding-top: 30px;
font-size: 50px;
padding-left: 30px;
font-family: 隶书;
.mainDiv
width: 899px;
height: 500px;
border: 4px rgb(237, 237, 237) solid;
border-radius: 5px;
background-image: url("https://img1.baidu.com/it/u=4271373647,1745018175&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500");
margin: auto;
margin-top: 50px;
background-size: auto;
.Navigation
width: 899px;
height: 200px;
background-color:#59c2c5;
opacity:0.8;
text-align: center;
line-height: 200px;
font-family: 楷体;
a
font-size:30px;
color:whitesmoke;
padding-left:20px;
text-decoration: none;
a:hover
color: blue;
font-family: 隶书;
</style>
</head>
<body>
<div class="mainDiv">
<div class="titleDiv">欢迎进入学生信息管理平台</div>
<%
if(session.getAttribute("login") == null)
session.setAttribute("loginErrorMessage", "您必须先登录才能访问主页!");
response.sendRedirect("index.jsp");
%>
<div class="Navigation">
<a href="addStudent.jsp">添加学生</a>
<a href="ShowStudentsByPageServlet">分页查询</a>
<a href="ShowAllStudentsServlet">查看所有学生信息</a>
<a href="QuitServlet">退出登录</a>
</div>
</div>
</body>
</html>
(4)添加学生界面 (addStudent.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>添加学生信息</title>
<style>
.titleDiv
height: 2px;
color:white;
padding-top: 12px;
font-size: 50px;
padding-left: 30px;
font-family: 隶书;
.mainDiv
width: 899px;
height: 500px;
border: 4px rgb(237, 237, 237) solid;
border-radius: 5px;
background-image: url("图片链接");
margin: auto;
margin-top: 50px;
background-size: auto;
.addDiv
height: 380px;
width: 260px;
padding:50px;
background-color:rgba(255,255,255,0.9);
border-radius:25px;
border:1px #bdbdbd solid;
opacity:0.9;
float: right;
margin-right: 80px
.name
font-size: 20px;
.item
height:60px;
.item input
line-height:40px;
width:245px;
border:none;
border-bottom: 1px solid #59c2c5;
margin-bottom: 20px;
margin-top: 10px;
.btn
display:block;
width:255px;
height:50px;
color:#fff;
background:#59c2c5;
font-size:16px;
line-height:30px;
text-align:center;
border-radius:10px;
border:none;
margin-top: 10px;
a
font-size:18px;
padding-left:200px;
padding-bottom: 50px;
color:#59c2c5;
</style>
</head>
<body>
<div class=javaweb简单的学生信息录入系统
Javaweb学生信息管理系统(Mysql+JSP+MVC+CSS)