软件环境
OS:Windows10
IDEA:2018.2
Java:jdk1.8
Mysql:8.0.13
Bootstrap:bootstrap.min.css
Juqery:jquery-ui-1.10.4.custom.min.css
Tomcat:8.5.23
Browser:Chrome
该图书管理系统实现了学生的成绩管理。学生实现了登录登出功能,查看成绩功能。教师端实现了注册登录,对学生成绩和信息进行增删改查的功能,实现Execl导出成绩功能。
数据库有三张表:一张是学生表(student),一张是教师表(teacher),一张是成绩表(score)。
下面是整个工程的截图
<%@ page import="dao.StudentDao" %>
<%@ page import="vo.Student" %>
<%@ page import="dao.ScoreDao" %>
<%@ page import="vo.Score" %>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/1
Time: 20:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>main</title>
<link href="../resources/css/default.css" rel="stylesheet"/>
</head>
<body style="background: #c3e6cb">
<%
Student student = (Student) session.getAttribute("info");
%>
<div id="page" class="container">
<div id="header">
<div id="logo">
<img src="../userImg/<%=student.getId()%>.jpeg"/>
<h1><%=student.getName()%></h1>
</div>
<div id="menu">
<ul>
<li><a href="personal.jsp">个人信息</a></li>
<li class="current_page_item"><a href="main.jsp">我的成绩</a></li>
<li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
</ul>
</div>
</div>
<div id="main">
<div class="top">
<h2 style="color: darkslateblue">我的成绩</h2>
<hr/>
</div>
<div class="table">
<table width="800" frame="box" align="center">
<tr>
<th height="35">学号/工号</th>
<th>姓名</th>
<th>学院</th>
<th>数据库</th>
<th>安卓</th>
<th>JSP</th>
<%--<th>操作</th>--%>
</tr>
<%
try {
ScoreDao scoD = new ScoreDao();
StudentDao stuD = new StudentDao();
Score stu = scoD.findWithId(student.getId());
String name = stuD.findWithId(student.getId()).getName();
String major = stuD.findWithId(student.getId()).getMajor();
%>
<tr>
<td height="35"><%=stu.getId()%></td>
<td><%=name%></td>
<td><%=major%></td>
<td><%=stu.getDatabase()%></td>
<td><%=stu.getAndroid()%></td>
<td><%=stu.getJsp()%></td>
<%--<td><a href="pdf.jsp?id=<%=stu.getId()%>&name=<%=name%>&major=<%=major%>&database=<%=stu.getDatabase()%>&android=<%=stu.getAndroid()%>&jsp=<%=stu.getJsp()%>">PDF</a></td>--%>
</tr>
<%
}
catch (Exception e){
out.print(e);
}
%>
</table>
</div>
</div>
</div>
</body>
</html>
<%@ page import="vo.Student" %>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/1
Time: 20:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>main</title>
<link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css">
<script src="../resources/js/jquery-1.10.2.js"></script>
<script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script>
<link href="../resources/css/default.css" rel="stylesheet"/>
</head>
<body style="background: #c3e6cb">
<%
Student student = (Student) session.getAttribute("info");
%>
<div id="page" class="container">
<div id="header">
<div id="logo">
<img src="../userImg/<%=student.getId()%>.jpeg"/>
<h1><%=student.getName()%></h1>
</div>
<div id="menu">
<ul>
<li class="current_page_item"><a href="personal.jsp" style="color: #10707f">个人信息</a></li>
<li><a href="main.jsp" style="color: #10707f">我的成绩</a></li>
<li><a onclick="return confirm('确认退出?');" href="../exit" style="color: #10707f">退出登录</a></li>
</ul>
</div>
</div>
<div id="main">
<div class="top">
<h2 style="color: darkslateblue">我的成绩</h2>
<hr/>
</div>
<div class="info">
<img src="../userImg/<%=student.getId()%>.jpeg" class="personalImg"><br>
<form action="../upload_studentImg" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<%=student.getId()%>">
<input type="file" name="img">
<input type="submit" value="上传头像">
</form>
<form action="../update_student_email" method="post">
<table width="400" frame="box" align="center" style="margin-top: 30px;">
<tr>
<td style="font-size: 25px;font-weight: bold">学号</td>
<td style="font-size: 25px;font-weight: bold"><%=student.getId()%></td>
</tr>
<tr>
<td style="font-size: 25px;font-weight: bold">姓名</td>
<td style="font-size: 25px;font-weight: bold"><%=student.getName()%></td>
</tr>
<tr>
<td style="font-size: 25px;font-weight: bold">性别</td>
<td style="font-size: 25px;font-weight: bold"><%=student.getSex()%></td>
</tr>
<tr>
<td style="font-size: 25px;font-weight: bold">学院</td>
<td style="font-size: 25px;font-weight: bold"><%=student.getMajor()%></td>
</tr>
</table>
</form>
<button class="password-btn" style="margin-top: 30px; height: 40px">修改安全信息</button>
</div>
</div>
</div>
<%--修改密码对话框--%>
<div id="password-dialog" title="修改安全信息" style="color: #004085">
<form id="password-form" method="post">
<input type="hidden" name="id" value="<%=student.getId()%>">
<%--邮箱: <input type="email" name="email" value="<%=student.getEmail()%>"><br><br>--%>
新密码:<input type="password" name="password"><br>
<hr>
<input style="float: right " type="submit" value="取消" onclick="function x() {
$('#add-dialog').dialog('close');
}">
<input style="float: right; margin-right: 25px" type="submit" value="保存"
onclick="this.form.action='../update_student_security'">
</form>
</div>
<script>
$('#password-dialog').dialog({
width: 340,
autoOpen: false,
draggable: false,
modal: true,
resizable: false
});
$('.password-btn').click(function () {
$('#password-dialog').dialog('open');
});
</script>
<style>
.ui-dialog-titlebar-close {
display: none
}
</style>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/28
Time: 19:56
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>重置密码</title>
<link rel="stylesheet" href="../resources/css/bootstrap.min.css">
<link href="../resources/css/forget.css" type="text/css" rel="stylesheet" />
</head>
<body style="background: #c3e6cb">
<h1 style="margin: 0px 80px; color:darkslateblue; font-family: STCaiyun">学生成绩管理系统</h1><br>
<%
String id = request.getParameter("id");
String email = request.getParameter("email");
String reset = request.getParameter("reset");
String code = (String) session.getAttribute("reset");
if (!reset.equals(code)){
%>
<script>alert("验证码错误!");window.location.href='../forget.jsp';</script>
<%
}
else {
%>
<div class="main">
<form role="form" action="../update_student_security" method="post">
<div class="form-group" align="center">
<input class="form-control" type="text" name="password" placeholder="新密码"><br>
<input type="hidden" name="id" value="<%=id%>">
<input type="hidden" name="email" value="<%=email%>">
<input type="submit" class="btn btn-success" value="提交">
<input type="button" class="btn btn-info" value="取消" style="margin-left: 20px" onclick="window.location.href='../login.jsp'">
</div>
</form>
</div>
<%
}
%>
<script src="../resources/js/jquery-3.2.1.min.js"></script>
<script src="../resources/js/popper.min.js"></script>
<script src="../resources/js/bootstrap.min.js"></script>
</body>
</html>
<%@ page import="java.util.ArrayList" %>
<%@ page import="vo.Student" %>
<%@ page import="vo.Teacher" %>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/1
Time: 20:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css">
<script src="../resources/js/jquery-1.10.2.js"></script>
<script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script>
<title>main</title>
<link href="../resources/css/default.css" rel="stylesheet"/>
</head>
<body style="background: #c3e6cb">
<%
Teacher teacher = (Teacher) session.getAttribute("info");
ArrayList<Student> stus = (ArrayList<Student>) session.getAttribute("onePageStudent");
int sumIndex = (int) session.getAttribute("sumIndex");
%>
<div id="page" class="container">
<div id="header">
logo部分
<div id="logo">
<img src="../userImg/<%=teacher.getId()%>.jpeg"/>
<h1><%=teacher.getId()%>
</h1>
</div>
<%-- 左面的功能栏 --%>
<div id="menu">
<ul>
<li><a href="personal.jsp">个人信息</a></li>
<li class="current_page_item"><a href="../one_page_student">学生信息管理</a></li>
<li><a href="../one_page_score">学生成绩管理</a></li>
<li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
</ul>
</div>
</div>
<div id="main">
<div class="top">
<h2 style="color: darkslateblue">学生成绩管理</h2>
<hr/>
<button class="btn-add" style="color: #2980b9">添加学生信息</button>
<div class="find">
<form action="../one_page_student" method="post">
<input id="find-text" type="text" name="key" placeholder="输入学号/工号或姓名搜索">
<input class="find-btn" type="submit" value="搜索">
</form>
</div>
</div>
<div class="table">
<table id="table" width="800" frame="box" align="center">
<tr>
<th height="35">学号/工号</th>
<th>姓名</th>
<th>性别</th>
<th>班级</th>
<th>学院</th>
<th>操作</th>
</tr>
<%
for (Student stu : stus) {
%>
<tr>
<form method="post" action="../update_student">
<td height="35"><%=stu.getId()%></td>
<td><input value="<%=stu.getName()%>" name="stuname" class="table-input"></td>
<td><input value="<%=stu.getSex()%>" name="stusex" class="table-input"></td>
<td><%=stu.getSchool_date()%></td>
<td><input value="<%=stu.getMajor()%>" name="stumajor" class="table-input" style="width: 110px"></td>
<input value="<%=stu.getId()%>" name="stuno" type="hidden">
<td><input type="submit" class="update-btn" value="修改">
<a class="btn-delete" onclick="return confirm('确定要删除吗?');"
href=<%="'../delete_student?id=" + stu.getId() + "'"%>>删除</a>
<a href="../one_page_score?id=<%=stu.getId()%>" style="color: #117a8b">学生成绩</a>
</td>
</form>
</tr>
<%
}
%>
</table>
</div>
<%
if (sumIndex > 1){
%>
<div id="index">
<a href="../one_page_student?index=1">首页</a>
<%
for (int i=1; i<=sumIndex; i++){
%>
<a href="../one_page_student?index=<%=i%>">第<%=i%>页</a>
<%
}
%>
<a href="../one_page_student?index=<%=sumIndex%>">尾页</a>
</div>
<%
}
%>
</div>
</div>
<%--添加学生信息对话框--%>
<div id="add-dialog" title="添加学生信息">
<form id="add-form" method="post">
学号:<input name="id" type="text"><br>
姓名:<input name="name" type="text"><br>
性别:<input name="sex" type="text"><br>
班级:<input name="school_date" type="text">
学院:<input name="major" type="text"><br>
<hr>
<input style="float: right" type="submit" value="取消" onclick="function x() {
$('#add-dialog').dialog('close');
}">
<input style="float: right; margin-right: 25px" type="submit" value="确定"
onclick="this.form.action='../add_student'">
</form>
</div>
<style>
.ui-dialog-titlebar-close {
display: none
}
</style>
<script>
$('#add-dialog').dialog({
width: 310,
autoOpen: false,
draggable: false,
modal: true,
resizable: false
});
$('.btn-add').click(function () {
$('#add-dialog').dialog('open');
});
</script>
</body>
</html>
<%@ page import="vo.Teacher" %>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/1
Time: 20:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>main</title>
<link href="../resources/css/default.css" rel="stylesheet"/>
</head>
<body style="background: #c3e6cb">
<%
Teacher teacher = (Teacher) session.getAttribute("info");
%>
<div id="page" class="container">
<div id="header">
<div id="logo">
<img src="../userImg/<%=teacher.getId()%>.jpeg"/>
<h1><%=teacher.getId()%>
</h1>
</div>
<div id="menu">
<ul>
<li class="current_page_item"><a href="personal.jsp">个人信息</a></li>
<li><a href="../one_page_student">学生信息管理</a></li>
<li><a href="../one_page_score">学生成绩管理</a></li>
<li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
</ul>
</div>
</div>
<div id="main">
<div class="top">
<h2 style="color: darkslateblue">个人信息</h2>
<hr/>
</div>
<div class="info">
<img src="../userImg/<%=teacher.getId()%>.jpeg" class="personalImg"><br>
<form action="../upload_teacherImg" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<%=teacher.getId()%>">
<input type="file" name="img">
<input type="submit" value="上传头像">
</form>
<form method="post" action="../update_teacher" class="personalForm">
<input name="uid" value="<%=teacher.getId()%>" type="hidden">
姓名: <input type="text" name="name" value="<%=teacher.getName()%>" class="personalInput"><br>
性别: <input type="text" name="sex" value="<%=teacher.getSex()%>" class="personalInput"><br>
邮箱: <input type="text" name="email" value="<%=teacher.getEmail()%>" class="personalInput"><br>
密码: <input type="text" name="password" value="<%=teacher.getPassword()%>" class="personalInput"><br>
<input type="submit" value="保存" style="width: 100px; height: 30px; margin-top: 20px">
</form>
</div>
</div>
</div>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/28
Time: 19:56
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>重置密码</title>
<link rel="stylesheet" href="../resources/css/bootstrap.min.css">
<link href="../resources/css/forget.css" type="text/css" rel="stylesheet" />
</head>
<body>
<h1 style="margin: 0px 80px; color:darkslateblue; font-family: STCaiyun">学生成绩管理系统</h1><br>
<%
String id = request.getParameter("id");
String reset = request.getParameter("reset");
String code = (String) session.getAttribute("reset");
if (!reset.equals(code)){
%>
<script>alert("验证码错误!");window.location.href='../forget.jsp';</script>
<%
} else {
%>
<div class="main">
<form role="form" action="../update_teacher_password" method="post">
<div class="form-group" align="center">
<input type="text" class="form-control" name="password" placeholder="新密码"><br>
<input type="hidden" name="id" value="<%=id%>">
<input type="submit" class="btn btn-success" value="提交">
<input type="button" class="btn btn-info" value="取消" style="margin-left: 20px" onclick="window.location.href='../login.jsp'">
</div>
</form>
</div>
<%
}
%>
<script src="../resources/js/jquery-3.2.1.min.js"></script>
<script src="../resources/js/popper.min.js"></script>
<script src="../resources/js/bootstrap.min.js"></script>
</body>
</html>
<%@ page import="vo.Teacher" %>
<%@ page import="vo.Score" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="dao.StudentDao" %>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/1
Time: 20:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>main</title>
<link href="../resources/css/default.css" rel="stylesheet"/>
</head>
<body style="background: #c3e6cb">
<%
Teacher teacher = (Teacher) session.getAttribute("info");
ArrayList<Score> stus = (ArrayList<Score>) session.getAttribute("onePageScore");
int sumIndex = (int) session.getAttribute("sumScoreIndex");
%>
<div id="page" class="container">
<div id="header">
<div id="logo">
<img src="../userImg/<%=teacher.getId()%>.jpeg"/>
<h1><%=teacher.getId()%>
</h1>
</div>
<div id="menu">
<ul>
<li><a href="personal.jsp">个人信息</a></li>
<li><a href="../one_page_student">学生信息管理</a></li>
<li class="current_page_item"><a href="../one_page_score">学生成绩管理</a></li>
<li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
</ul>
</div>
</div>
<div id="main">
<div class="top">
<h2 style="color: darkslateblue">学生成绩管理</h2>
<hr/>
</div>
<form method="post" action="../update_score" style="height: 525px; margin-top: 20px">
<input type="button" class="btn-add" onclick="location.href='score_excel.jsp';" value="导出EXCEL">
<input type="submit" class="btn-add" style="float: right;margin-bottom: 30px" value="修改">
<div class="table" style="margin-top: 20px; height: 525px">
<table id="table" width="800" frame="box" align="center">
<tr>
<th height="35">学号</th>
<th>姓名</th>
<th>学院</th>
<th>数据库</th>
<th>安卓</th>
<th>JSP</th>
</tr>
<%
try {
StudentDao stuD = new StudentDao();
for (Score stu : stus) {
String name = stuD.findWithId(stu.getId()).getName();
String major = stuD.findWithId(stu.getId()).getMajor();
%>
<tr>
<td height="35"><%=stu.getId()%></td>
<td><%=name%></td>
<td><%=major%></td>
<td><input value="<%=stu.getDatabase()%>" name="database" class="table-input"></td>
<td><input value="<%=stu.getAndroid()%>" name="android" class="table-input"></td>
<td><input value="<%=stu.getJsp()%>" name="jsp" class="table-input"></td>
<input value="<%=stu.getId()%>" name="id" type="hidden">
</tr>
<%
}
} catch (Exception e) {
e.printStackTrace();
}
%>
</table>
</div>
</form>
<%-- 展示下面的页签数 --%>
<%
if (sumIndex > 1){
%>
<div id="index">
<a href="../one_page_score?index=1">首页</a>
<%
for (int i = 1; i <= sumIndex; i++) {
%>
<a href="../one_page_score?index=<%=i%>">第<%=i%>页</a>
<%
}
%>
<a href="../one_page_score?index=<%=sumIndex%>">尾页</a>
</div>
<%
}
%>
</div>
</div>
</body>
</html>
<%@ page import="dao.ScoreDao" %>
<%@ page import="vo.Score" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="dao.StudentDao" %>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/1
Time: 20:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="application/msexcel" language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title>main</title>
</head>
<body style="background: #c3e6cb">
<%
out.clearBuffer();
response.setHeader("Content-Disposition", "attachment;filename=excel.xls");
%>
<table align="center" border="1">
<tr>
<th height="35">学号</th>
<th>姓名</th>
<th>学院</th>
<th>数据库</th>
<th>安卓</th>
<th>JSP</th>
</tr>
<%
try {
ScoreDao scoD = new ScoreDao();
StudentDao stuD = new StudentDao();
ArrayList<Score> stus = scoD.getOnePage(1, 10000);
for (Score stu : stus) {
String name = stuD.findWithId(stu.getId()).getName();
String major = stuD.findWithId(stu.getId()).getMajor();
%>
<tr>
<td align="center"><%=stu.getId()%></td>
<td align="center"><%=name%></td>
<td align="center"><%=major%></td>
<td align="center"><%=stu.getDatabase()%></td>
<td align="center"><%=stu.getAndroid()%></td>
<td align="center"><%=stu.getJsp()%></td>
</tr>
<%
}
} catch (Exception e) {
e.printStackTrace();
}
%>
</table>
</body>
</html>
<%@ page import="java.awt.image.BufferedImage" %>
<%@ page import="java.awt.*" %>
<%@ page import="java.util.Random" %>
<%@ page import="javax.imageio.ImageIO" %>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/22
Time: 18:48
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="image/JPEG;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
response.setCharacterEncoding("utf-8");
response.setHeader("Cache-Control", "no-cache");
//创建图像
int width = 60, height = 20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//获取画笔
Graphics g = image.getGraphics();
//设定背景色
g.setColor(new Color(100, 200, 200));
g.fillRect(0, 0, width, height);
//随机产生四位数字
Random rnd = new Random();
int randNum = rnd.nextInt(8999) + 1000;
String randStr = String.valueOf(randNum);
//将验证码存入session
session.setAttribute("randStr", randStr);
//显示到图像中
g.setColor(Color.BLACK);
g.setFont(new Font("", Font.PLAIN, 20));
g.drawString(randStr, 10, 17);
//随机产生100个干扰点
for (int i = 0; i < 100; i++) {
int x = rnd.nextInt(width);
int y = rnd.nextInt(height);
g.drawOval(x, y, 1, 1);
}
//输出到页面
ImageIO.write(image, "jpeg", response.getOutputStream());
out.clear();
out = pageContext.pushBody();
%>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/1
Time: 20:16
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>请登陆</title>
<link rel="stylesheet" href="resources/css/bootstrap.min.css">
<link href="resources/css/login.css" type="text/css" rel="stylesheet" />
</head>
<body>
<script>
function check(form){
if (form.user.value === "") {
alert("请输入账号!");
return false;
}
if (form.password.value === "") {
alert("请输入密码!");
return false;
}
return true;
}
</script>
<h1>学生成绩管理系统</h1><br>
<div class="main">
<h5 class="title">
<a href="login.jsp" id="login">登录</a>
<b> · </b>
<a href="register.jsp" id="register">注册</a>
</h5>
<form action="check_login" method="post" onsubmit="return check(this)">
<div class="form-group" >
<input type="text" name="user" class="form-control user" placeholder="请输入用户名">
<input type="password" name="password" class="form-control password" placeholder="请输入密码">
<div class="remember-btn">
<input type="checkbox" name="remember" value="true">
<span style="color: #d4edda">记住我</span>
</div>
<%--<a href="forget.jsp" class="help" style="color: #1b1e21">登录遇到问题?</a>--%>
<input type="submit" value="登录" class="btn btn-primary btn-lg btn-block" />
</div>
</form>
</div>
<script src="resources/js/jquery-3.2.1.min.js"></script>
<script src="resources/js/popper.min.js"></script>
<script src="resources/js/bootstrap.min.js"></script>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: 007
Date: 2018/11/1
Time: 20:26
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>注册</title>
<link rel="stylesheet" href="resources/css/bootstrap.min.css">
<link href="resources/css/register.css" type="text/css" rel="stylesheet" />
</head>
<body>
<script>
function check(form){
if (form.user.value === "") {
alert("请输入账号!");
return false;
}
if (form.password1.value === "") {
alert("请输入密码!");
return false;
}
return true;
}
function refresh() {
var i=Math.random();
document.getElementById("image").src = "code.jsp?a="+i;
}
</script>
<h1>学生成绩管理系统</h1><br>
<div class="main">
<h5 class="title" >
<a href="login.jsp" id="login">登录</a>
<b> · </b>
<a href="register.jsp" id="register">注册</a>
</h5>
<form action="check_register" method="post" onsubmit="return check(this)">
<div class="form-group">
<input type="email" name="email" class="form-control email" placeholder="安全邮箱">
<input type="text" name="user" class="form-control user" placeholder="用户名">
<input type="password" name="password1" class="form-control password1" placeholder="密码">
<input type="text" name="code" placeholder="验证码" class="code">
<img src="code.jsp" id="image" style="float: right; width: 90px;height: 50px; margin-top: 10px" onclick="refresh()">
<input type="submit" value="注册" class="btn btn-primary btn-lg btn-block we" />
</div>
</form>
</div>
<script src="resources/js/jquery-3.2.1.min.js"></script>
<script src="resources/js/popper.min.js"></script>
<script src="resources/js/bootstrap.min.js"></script>
</body>
</html>
package vo;
/**
* 分数类
*/
public class Score {
private String id;
private String database;
private String android;
private String jsp;
public String getId(){
return id;
}
public String getDatabase(){
return database;
}
public String getAndroid(){
return android;
}
public String getJsp(){
return jsp;
}
public void setId(String id){
this.id = id;
}
public void setDatabase(String database){
this.database = database;
}
public void setAndroid(String android){
this.android = android;
}
public void setJsp(String jsp){
this.jsp = jsp;
}
}
package vo;
import java.sql.Date;
import java.sql.PseudoColumnUsage;
import java.util.regex.Pattern;
/**
*学生类
*/
public class Student {
private String id;
private String password;
private String name;
private String sex;
private String school_date;
private String major;
private String email;
public String getId(){
return id;
}
public String getPassword(){
return password;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public String getSchool_date(){
return school_date;
}
public String getMajor(){
return major;
}
public String getEmail(){
return email;
}
public void setId(String id){
this.id = id;
}
public void setPassword(String password){
this.password = password;
}
public void setName(String name){
this.name = name;
}
public void setSex(String sex){
this.sex = sex;
}
public void setSchool_date(String school_date){
this.school_date = school_date;
}
public void setMajor(String major){
this.major = major;
}
public void setEmail(String email){
this.email = email;
}
}
package vo;
/**
* 教师类
*/
public class Teacher {
private String id;
private String password;
private String email;
private String name;
private String sex;
public String getId(){
return id;
}
public String getPassword(){
return password;
}
public String getEmail(){
return email;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public void setId(String id){
this.id = id;
}
public void setPassword(String password){
this.password = password;
}
public void setEmail(String email){
this.email= email;
}
public void setName(String name){
this.name = name;
}
public void setSex(String sex){
this.sex = sex;
}
}
package dao;
import vo.Score;
import java.sql.*;
import java.util.ArrayList;
public class ScoreDao {
private Connection conn = null;
// 定义数据常量
static String driver = "com.mysql.cj.jdbc.Driver";
static String url = "jdbc:mysql://localhost:3306/student_manager?serverTimezone=UTC";
static String user = "root";
static String password="admin";
/**
* 录入成绩
* @param id
* @return
* @throws Exception
*/
public boolean insertScore(String id) throws Exception{
initConnection();
String sql = "insert into score(id) values(?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, id);
int i = ps.executeUpdate();
closeConnection();
return i == 1;
}
/**
* 删除成绩
* @param id
* @return
* @throws Exception
*/
public boolean deleteScore(String id) throws Exception{
initConnection();
Statement stat = conn.createStatement();
String sql = "delete from score where id='"+id+"'";
int i = stat.executeUpdate(sql);
closeConnection();
return i==1;
}
/**
* 更新成绩
* @param id
* @param database
* @param android
* @param jsp
* @throws Exception
*/
public void updateScoreInfo(String id, String database, String android, String jsp) throws Exception{
initConnection();
String sql = "update score set dat=?, android=?, jsp=? where id=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, database);
ps.setString(2, android);
ps.setString(3, jsp);
ps.setString(4, id);
ps.executeUpdate();
closeConnection();
}
/**
* 以id查找信息
* @param id
* @return
* @throws Exception
*/
public Score findWithId(String id) throws Exception{
initConnection();
Statement stat = conn.createStatement();
String sql = "select * from score where id = '" + id + "'";
ResultSet rs = stat.executeQuery(sql);
Score stu = getScore(rs);
closeConnection();
return stu;
}
/**
* 分页查询
* @param page
* @param size
* @return
* @throws Exception
*/
public ArrayList<Score> getOnePage(int page, int size) throws Exception{
ArrayList<Score> al = new ArrayList<>();
initConnection();
String sql = "SELECT * FROM score limit ?, ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, (page-1)*size);
ps.setInt(2, size);
ResultSet rs = ps.executeQuery();
getMoreScore(al, rs);
closeConnection();
return al;
}
/**
* 查询总数
* @return
* @throws Exception
*/
public int getScoreCount() throws Exception{
initConnection();
String sql = "select count(*) from score";
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(sql);
rs.next();
int count = rs.getInt(1);
closeConnection();
return count;
}
/**
* 获取成绩
* @param rs
* @return
* @throws SQLException
*/
private Score getScore(ResultSet rs) throws SQLException {
Score stu = null;
if (rs.next()){
stu = new Score();
stu.setId(rs.getString("id"));
stu.setDatabase(rs.getString("dat"));
stu.setAndroid(rs.getString("android"));
stu.setJsp(rs.getString("jsp"));
}
return stu;
}
/**
* 获取所有成绩
* @param al
* @param rs
* @throws SQLException
*/
private void getMoreScore(ArrayList<Score> al, ResultSet rs) throws SQLException {
while (rs.next()){
Score score = new Score();
score.setId(rs.getString("id"));
score.setDatabase(rs.getString("dat"));
score.setAndroid(rs.getString("android"));
score.setJsp(rs.getString("jsp"));
al.add(score);
}
}
/**
* 初始化数据库连接
* @throws Exception
*/
private void initConnection() throws Exception {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
}
/**
* 关闭连接
* @throws Exception
*/
private void closeConnection() throws Exception{
conn.close();
}
}
package dao;
import vo.Student;
import java.sql.*;
import java.util.ArrayList;
/**
* @author shuijianshiqing
* @date 2020/6/11 20:40
* 操作教师信息
*/
public class StudentDao {
private Connection conn = null;
// 定义数据常量
static String driver = "com.mysql.cj.jdbc.Driver";
static String url = "jdbc:mysql://localhost:3306/student_manager?serverTimezone=UTC";
static String user = "root";
static String password="admin";
/**
* 验证学生账号和密码
* @param user
* @param password
* @return
* @throws Exception
*/
public Student checkAccount(String user, String password) throws Exception {
initConnection();
Statement stat = conn.createStatement();
String sql = "select * from student where id = '" + user + "' and password = '" + password + "'";
ResultSet rs = stat.executeQuery(sql);
Student stu = getStudent(rs);
closeConnection();
return stu;
}
/**
* 使用学生id来查找学生信息
* @param id
* @return
* @throws Exception
*/
public Student findWithId(String id) throws Exception{
initConnection();
Statement stat = conn.createStatement();
String sql = "select * from student where id = '" + id + "'";
ResultSet rs = stat.executeQuery(sql);
Student stu = getStudent(rs);
closeConnection();
return stu;
}
/**
* 使用学生姓名查找学生信息
* @param name
* @return
* @throws Exception
*/
public ArrayList<Student> findWithName(String name) throws Exception{
ArrayList<Student> al = new ArrayList<>();
initConnection();
Statement stat = conn.createStatement();
String sql = "select * from student where name = '" + name + "'";
ResultSet rs = stat.executeQuery(sql);
getMoreStudent(al, rs);
closeConnection();
return al;
}
/**
* 添加学生信息
* @param id
* @param name
* @param sex
* @param school_date
* @param major
* @return
* @throws Exception
*/
public boolean insertStudent(String id, String name, String sex, String school_date, String major) throws Exception{
initConnection();
String sql = "insert into student(id, name, sex, school_date, major) values(?, ?, ?, ?, ?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, id);
ps.setString(2, name);
ps.setString(3, sex);
ps.setString(4, school_date);
ps.setString(5, major);
int i = ps.executeUpdate();
closeConnection();
return i == 1;
}
/**
* 删除学生信息
* @param id
* @return
* @throws Exception
*/
public boolean deleteStudent(String id) throws Exception{
initConnection();
Statement stat = conn.createStatement();
String sql = "delete from student where id='"+id+"'";
int i = stat.executeUpdate(sql);
closeConnection();
return i==1;
}
/**
* 获取每页的信息
* @param page
* @param size
* @return
* @throws Exception
*/
public ArrayList<Student> getOnePage(int page, int size) throws Exception{
ArrayList<Student> al = new ArrayList<>();
initConnection();
String sql = "SELECT * FROM student limit ?, ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, (page-1)*size);
ps.setInt(2, size);
ResultSet rs = ps.executeQuery();
getMoreStudent(al, rs);
closeConnection();
return al;
}
/**
* 获取学生总数
* @return
* @throws Exception
*/
public int getStudentCount() throws Exception{
initConnection();
String sql = "select count(*) from student";
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(sql);
rs.next();
int count = rs.getInt(1);
closeConnection();
return count;
}
/**
* 更新学生信息
* @param id
* @param name
* @param sex
* @param major
* @throws Exception
*/
public void updateStudentInfo(String id, String name, String sex, String major) throws Exception{
initConnection();
String sql = "update student set name=?, sex=?, major=? where id=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, sex);
ps.setString(3, major);
ps.setString(4, id);
ps.executeUpdate();
closeConnection();
}
/**
* 更新学生密码和邮件
* @param id
* @param email
* @param password
* @throws Exception
*/
public void updateStudentSecurity(String id, String email, String password) throws Exception{
initConnection();
String sql = "update student set password=?, email=? where id=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, password);
ps.setString(2, email);
ps.setString(3, id);
ps.executeUpdate();
closeConnection();
}
/**
* 获取单个学生信息
* @param rs
* @return
* @throws SQLException
*/
private Student getStudent(ResultSet rs) throws SQLException {
Student stu = null;
if (rs.next()){
stu = new Student();
stu.setId(rs.getString("id"));
stu.setPassword(rs.getString("password"));
stu.setName(rs.getString("name"));
stu.setSex(rs.getString("sex"));
stu.setSchool_date(rs.getString("school_date"));
stu.setMajor(rs.getString("major"));
stu.setEmail(rs.getString("email"));
}
return stu;
}
/**
* 获取多个学生信息
* @param al
* @param rs
* @throws SQLException
*/
private void getMoreStudent(ArrayList<Student> al, ResultSet rs) throws SQLException {
while (rs.next()){
Student stu = new Student();
stu.setId(rs.getString("id"));
stu.setPassword(rs.getString("password"));
stu.setName(rs.getString("name"));
stu.setSex(rs.getString("sex"));
stu.setSchool_date(rs.getString("school_date"));
stu.setMajor(rs.getString("major"));
stu.setEmail(rs.getString("email"));
al.add(stu);
}
}
/**
* 初始化数据库连接
* @throws Exception
*/
private void initConnection() throws Exception {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
}
/**
* 关闭连接
* @throws Exception
*/
private void closeConnection() throws Exception{
conn.close();
}
}
package dao;
import vo.Teacher;
import java.sql.*;
/**
* @author shuijianshiqing
* @date 2020/6/11 20:40
* 操作教师信息
*/
public class TeacherDao {
// 定义连接
private Connection conn = null;
// 定义数据常量
static String driver = "com.mysql.cj.jdbc.Driver";
static String url = "jdbc:mysql://localhost:3306/student_manager?serverTimezone=UTC";
static String user = "root";
static String password="admin";
/**
* 验证教师登录的账号和密码
* @param id
* @param password
* @return
* @throws Exception
*/
public Teacher checkAccount(String id, String password) throws Exception {
initConnection();
Statement stat = conn.createStatement();
String sql = "select * from teacher where id = '" + id + "' and password = '" + password + "'";
ResultSet rs = stat.executeQuery(sql);
Teacher tea = getTeacher(rs);
closeConnection();
return tea;
}
/**
* 使用教师id来查询教师信息
* @param id
* @return
* @throws Exception
*/
public Teacher findWithId(String id) throws Exception {
initConnection();
Statement stat = conn.createStatement();
String sql = "select * from teacher where id = '" + id + "'";
ResultSet rs = stat.executeQuery(sql);
Teacher tea = getTeacher(rs);
closeConnection();
return tea;
}
/**
* 添加教师信息
* @param id
* @param password
* @param email
* @return
* @throws Exception
*/
public Teacher insertTeacher(String id, String password, String email) throws Exception {
initConnection();
String sql = "insert into teacher(id, password, email) values(?, ?, ?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, id);
ps.setString(2, password);
ps.setString(3, email);
ps.executeUpdate();
Teacher teacher = findWithId(id);
closeConnection();
return teacher;
}
/**
* 更新教师信息
* @param id
* @param name
* @param sex
* @param email
* @param password
* @return
* @throws Exception
*/
public Teacher updateTeacher(String id, String name, String sex, String email, String password) throws Exception{
initConnection();
String sql = "update teacher set name=?, sex=?, email=?, password=? where id=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, sex);
ps.setString(3, email);
ps.setString(4, password);
ps.setString(5, id);
ps.executeUpdate();
Teacher teacher = findWithId(id);
closeConnection();
return teacher;
}
/**
* 更新教师密码
* @param id
* @param password
* @throws Exception
*/
public void updateTeacherPassword(String id, String password) throws Exception{
initConnection();
String sql = "update teacher set password=? where id=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, password);
ps.setString(2, id);
ps.executeUpdate();
closeConnection();
}
/**
* 根据ResultSet来获取教师信息
* @param rs
* @return
* @throws SQLException
*/
private Teacher getTeacher(ResultSet rs) throws SQLException {
Teacher tea = null;
if (rs.next()) {
tea = new Teacher();
tea.setId(rs.getString("id"));
tea.setPassword(rs.getString("password"));
tea.setName(rs.getString("name"));
tea.setEmail(rs.getString("email"));
tea.setSex(rs.getString("sex"));
}
return tea;
}
/**
* 初始化数据库连接
* @throws Exception
*/
private void initConnection() throws Exception {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
}
/**
* 关闭连接
* @throws Exception
*/
private void closeConnection() throws Exception {
conn.close();
}
/**
* 测试数据库连接
* @param args
*/
public static void main(String[] args) throws Exception{
TeacherDao dao = new TeacherDao();
dao.initConnection();
System.out.println("数据库连接成功");
dao.closeConnection();
}
}
package servlet;
import dao.ScoreDao;
import dao.StudentDao;
import dao.StudentDao;
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.io.PrintWriter;
/**
* 添加学生信息
*/
@WebServlet("/add_student")
public class add_student extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
StudentDao studentDao = new StudentDao();
ScoreDao scoreDao = new ScoreDao();
String id = request.getParameter("id");
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String major = request.getParameter("major");
String school_date = request.getParameter("school_date");
try {
// 添加学生信息
studentDao.insertStudent(id, name, sex, school_date, major);
// 添加分数信息
scoreDao.insertScore(id);
}
catch (Exception e){
out.print(e);
}
response.sendRedirect("one_page_student");
}
}
package servlet;
import dao.StudentDao;
import dao.TeacherDao;
import vo.Student;
import vo.Teacher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
/**
* 检查登录
*/
@WebServlet("/check_login")
public class check_login extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
// 账号
String user = request.getParameter("user");
// 密码
String password = request.getParameter("password");
// 是否记住密码
String remember = request.getParameter("remember");
// 创建Dao层
TeacherDao teacherDao = new TeacherDao();
StudentDao studentDao = new StudentDao();
// 创建实体类
Teacher teacher = null;
Student student = null;
try {
// 判断用户身份
teacher = teacherDao.checkAccount(user, password);
student = studentDao.checkAccount(user, password);
}
catch (Exception e) {
out.print(e);
}
if (teacher != null) {
//向session中添加用户信息
session.setAttribute("info", teacher);
//检查用户是否需要保持登录状态
if (remember != null) {
//发送cookie到客户端
Cookie userCookie = new Cookie("name", user);
userCookie.setMaxAge(10);
response.addCookie(userCookie);
}
// 重定向
response.sendRedirect("one_page_student");
}
else if (student != null){
//向session中添加用户信息
session.setAttribute("info", student);
//检查用户是否需要保持登录状态
if (remember != null) {
//发送cookie到客户端
Cookie userCookie = new Cookie("name", user);
userCookie.setMaxAge(10);
response.addCookie(userCookie);
}
response.sendRedirect("student/main.jsp");
}
else {
out.print("");
} else {
TeacherDao teacherDao = new TeacherDao();
Teacher teacher = null;
try {
teacher = teacherDao.insertTeacher(user, password, email);
} catch (Exception e) {
out.print(e);
}
if (teacher != null) {
//向session中添加用户信息
session.setAttribute("info", teacher);
response.sendRedirect("one_page_student");
} else {
out.print("");
}
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package servlet;
import dao.ScoreDao;
import dao.StudentDao;
import dao.StudentDao;
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.io.PrintWriter;
/**
* 删除学生信息
*/
@WebServlet("/delete_student")
public class delete_student extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
StudentDao studentDao = new StudentDao();
ScoreDao scoreDao = new ScoreDao();
String id = request.getParameter("id");
try {
// 删除学生
studentDao.deleteStudent(id);
// 删除成绩
scoreDao.deleteScore(id);
response.sendRedirect("one_page_student");
}
catch (Exception e){
out.print(e);
}
}
}
package servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* 退出登录
*/
@WebServlet("/exit")
public class exit extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//清除cookie, 跳到起始页
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie c : cookies) {
String cookieName = c.getName();
if ("name".equals(cookieName)) {
c.setMaxAge(0);
response.addCookie(c);
}
}
}
response.sendRedirect("index.jsp");
}
}
package servlet;
import dao.ScoreDao;
import vo.Score;
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 javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
/**
* 分数分页
*/
@WebServlet("/one_page_score")
public class one_page_score extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
// 获取传入id的值
String key = request.getParameter("id");
if (key == null) {
int currentIndex, count, size = 10;
String index = request.getParameter("index");
if (index == null)
index = "1";
currentIndex = Integer.parseInt(index);
try {
ScoreDao scoD = new ScoreDao();
count = scoD.getScoreCount();
ArrayList<Score> stus = scoD.getOnePage(currentIndex, size);
int sumIndex = count % size == 0 ? count / size : count / size + 1;
session.setAttribute("onePageScore", stus);
session.setAttribute("sumScoreIndex", sumIndex);
response.sendRedirect("teacher/score.jsp");
} catch (Exception e) {
out.print(e);
}
}
else {
ScoreDao scoreDao = new ScoreDao();
try {
Score score = scoreDao.findWithId(key);
ArrayList<Score> scores = new ArrayList<>();
scores.add(score);
session.setAttribute("onePageScore", scores);
session.setAttribute("sumScoreIndex", 1);
response.sendRedirect("teacher/score.jsp");
} catch (Exception e) {
out.print(e);
}
}
}
}
package servlet;
import dao.StudentDao;
import vo.Student;
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 javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.regex.Pattern;
/**
*学生分页
*/
@WebServlet("/one_page_student")
public class one_page_student extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
// 获取key的值
String key = request.getParameter("key");
// 如果key为空或者空字符串
if (key == null || key.equals("")) {
int currentIndex, count, size = 10;
String index = request.getParameter("index");
if (index == null)
index = "1";
// 当前页赋值
currentIndex = Integer.parseInt(index);
try {
StudentDao sdao = new StudentDao();
// 查询当前页信息
ArrayList<Student> stus = sdao.getOnePage(currentIndex, size);
count = sdao.getStudentCount();
// 计算总页数
int sumIndex = count % size == 0 ? count / size : count / size + 1;
session.setAttribute("onePageStudent", stus);
session.setAttribute("sumIndex", sumIndex);
response.sendRedirect("teacher/main.jsp");
} catch (Exception e) {
out.print(e);
}
}
else {
StudentDao studentDao = new StudentDao();
// 这里前一个"\"是转义字符,后一个是字符串,这个字符串表示数字至少出现一次
String pattern = "^\\d+";
boolean isMatch = Pattern.matches(pattern, key);
if (isMatch) {
try {
// 某个学生的信息
Student student = studentDao.findWithId(key);
ArrayList<Student> students = new ArrayList<>();
students.add(student);
session.setAttribute("onePageStudent", students);
session.setAttribute("sumIndex", 1);
response.sendRedirect("teacher/main.jsp");
} catch (Exception e) {
out.print(e);
}
} else {
try {
ArrayList<Student> stus = studentDao.findWithName(key);
session.setAttribute("onePageStudent", stus);
session.setAttribute("sumIndex", 1);
response.sendRedirect("teacher/main.jsp");
} catch (Exception e) {
out.print(e);
}
}
}
}
}
package servlet;
import dao.ScoreDao;
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.io.PrintWriter;
/**
* 更新成绩
*/
@WebServlet("/update_score")
public class update_score extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
ScoreDao scoreDao = new ScoreDao();
// 把要修改的值存下来
String[] id = request.getParameterValues("id");
String[] database = request.getParameterValues("database");
String[] android = request.getParameterValues("android");
String[] jsp = request.getParameterValues("jsp");
try {
// 循环去更新
for (int i=0; i<id.length; i++) {
scoreDao.updateScoreInfo(id[i], database[i], android[i], jsp[i]);
}
response.sendRedirect("one_page_score");
}
catch (Exception e){
out.print(e);
}
}
}
package servlet;
import dao.StudentDao;
import dao.StudentDao;
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.io.PrintWriter;
/**
* 更新学生信息
*/
@WebServlet("/update_student")
public class update_student extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
StudentDao studentDao = new StudentDao();
String stuno = request.getParameter("stuno");
String stuname = request.getParameter("stuname");
String stusex = request.getParameter("stusex");
String stumajor = request.getParameter("stumajor");
try {
// 更新学生信息
studentDao.updateStudentInfo(stuno, stuname, stusex, stumajor);
}
catch (Exception e){
out.print(e);
}
response.sendRedirect("one_page_student");
}
}
package servlet;
import dao.TeacherDao;
import vo.Teacher;
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 javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
/**
* 更新教师信息
*/
@WebServlet("/update_teacher")
public class update_teacher extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
TeacherDao teacherDao = new TeacherDao();
String uid = request.getParameter("uid");
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String email = request.getParameter("email");
String password = request.getParameter("password");
try {
// 更新教师信息
Teacher teacher = teacherDao.updateTeacher(uid, name, sex, email, password);
session.setAttribute("info", teacher);
out.print("");
}
catch (Exception e){
out.print(e);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package servlet;
import com.jspsmart.upload.File;
import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import javax.servlet.ServletConfig;
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.io.PrintWriter;
/**
* 更新学生头像
*/
@WebServlet("/upload_studentImg")
public class upload_studentImg extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
SmartUpload smartUpload = new SmartUpload();
Request rq = smartUpload.getRequest();
ServletConfig config = this.getServletConfig();
smartUpload.initialize(config, request, response);
try {
//上传文件
smartUpload.upload();
String id = rq.getParameter("id");
File smartFile = smartUpload.getFiles().getFile(0);
smartFile.saveAs("/userImg/"+id+".jpeg");
out.print("");
}
catch (Exception e){
out.print(e);
}
}
}
package servlet;
import com.jspsmart.upload.File;
import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import javax.servlet.ServletConfig;
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.io.PrintWriter;
/**
* 更新教师头像
*/
@WebServlet("/upload_teacherImg")
public class upload_teacherImg extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
SmartUpload smartUpload = new SmartUpload();
Request rq = smartUpload.getRequest();
ServletConfig config = this.getServletConfig();
smartUpload.initialize(config, request, response);
try {
//上传文件
smartUpload.upload();
String id = rq.getParameter("id");
File smartFile = smartUpload.getFiles().getFile(0);
smartFile.saveAs("/userImg/"+id+".jpeg");
out.print("");
}
catch (Exception e){
out.print(e);
}
}
}
itextpdf-5.5.5.jar
javax.annotation.jar
javax.ejb.jar
javax.jms.jar
javax.persistence.jar
javax.resource.jar
javax.servlet.jar
javax.servlet.jsp.jar
javax.servlet.jsp.jstl.jar
javax.transaction.jar
jsmartcom_zh_CN.jar
mysql-connector-java-8.0.15.jar
这个系统用到了Servlet,相较于上个项目,很多页面的逻辑可以转到后台进行处理,前端的jsp页面省了好多事情。这样前端页面加载也快一点。
这个项目是从学妹哪里拿过来的,自己做了一些代码的注释和修改工作,这个项目基本的JavaEE的知识点都包括了。但是没有用到日志框架,不过用来做简单的课程设计是绰绰有余了。
要是需要图书管理系统的可以访问博客,请移步:
图书管理系统
图书管理系统-添加管理增删改查功能
要是不知道IDEA如何搭建WEB项目,请移步:
IDEA创建Web项目详细说明
请联系QQ:3079118617
如果要是侵犯到您的权益请通知我删除。