Javaweb学生信息管理系统(Mysql+JSP+MVC+CSS)

时间:2024-10-12 22:35:40

目录

一.项目介绍

二.运行效果

1.登录界面

2.主界面(点击学号修改学生信息)

3.增加学生界面

?编辑

三.项目目录结构

?四.代码展示

及css代码

?①登录界面代码()

②登录界面css()

③注册用户界面()

④注册用户界面css()

⑤修改密码界面()

⑥注销用户界面()

⑦登录成功主界面()

⑧登陆成功界面css()

⑨点击学号,修改学生信息界面()

⑩增加学生信息()

?上传作业操作()

2.三层架构

①表示层Servlet

②业务逻辑层Service

③数据访问层Dao

④通用的数据库操作()

封装数据

①分页帮助类()

②封装学生信息()

4.项目所需jar包

五.数据库表格

①登录注册表格login

②学生信息表格student1


一.项目介绍

本系统主要实现对基于Javaweb学生信息管理系统所需的各项基本功能,能够对学生信息进行增删改查等功能,并可以实现用户注册、用户登陆等功能。

数据库:Mysql

开发工具:Eclipse

开发环境:JDK+Tomcat

二.运行效果

1.登录界面

2.主界面(点击学号修改学生信息)

3.增加学生界面

三.项目目录结构

四.代码展示

及css代码

①登录界面代码()

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link href="css/" type="text/css" rel="stylesheet">
<meta charset="UTF-8">

<title>学生信息管理系统-登录界面</title>
</head>
<body>
	<form action="CheckLoginServlet" method="post">
		<div class="content">
			<div class="wrap">
				<div class="login-box">
					<div class="login-frame">
						<h2>
							用户登录 <a href=""> 立即注册</a>
						</h2>
						<div class=item>
							<input type="text" name="UID" placeholder="用户名">
						</div>
						<div class=item>
							<input type="password" name="upwd" placeholder="密码">
						</div>
						<input type="submit" class="login-btn" value="登 录">
						<div class=item1>
							<a href=""> 修改密码</a> 
							<a	href=""> 注销用户</a>
						</div>
						<%
							String error = (String) ("error");
							String error0 = (String) ("error0");
							String error1 = (String) ("error1");
							String error2 = (String) ("error2");
							String error3 = (String) ("error3");
							String error4 = (String) ("error4");

							if (error != null) {
								if (("loginError")) {
									("用户名或密码错误!登录失败!");
								} else if (("nologinError")) {
									("QueryStudentByPageServlet");
								}
							}

							if (error0 != null) {
								if (("loginError")) {
									("用户名或密码错误!修改失败!");
								} else if (("nologinError")) {
									if (error1 != null) {
								if (("noupdateError")) {
									("密码修改成功!");
								}
									}
								}
							}
							if (error2 != null) {
								if (("loginError")) {
									("用户名或密码错误!注销失败!");
								} else if (("nologinError")) {
									if (error3 != null) {
								if (("nodeleteError")) {
									("账户注销成功!");
								}
									}
								}
							}
							if (error4 != null) {
								if (("noaddError")) {
									("账户注册成功!");
								}
							}
							%>
						</div>
					</div>
				</div>
			</div>
	</form>

</body>



</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85

②登录界面css()

*{margin:0;padding:0;}
a{text-decoration:none;color:#666;}
a:hover{
	text-decoration:underline;
	color:E4393C;
}
html,body
{
	font:12px/150% Arial,Verdana;
}

.wrap{
	width:1000px;
	margin:0 auto;
}
.left{
	float:left;
}

.content{
	background:url(../image/);
	background-size: cover;
	width:1280px;
	height:559px;
}

.login-frame{
	margin:50px 5% 50px 5%;
	float:right;
	padding:60px;
	background:white;
	background-color:rgba(255,255,255,0.9);
	border-radius:25px;
	order-right:1px #bdbdbd solid;
	width:280px;
	height:230px;
}


.login-frame h2{
	font-size:25px;
	height:40px;
	margin-buttom:25px;
}
.login-frame h2 a{
	font-size:15px;
	color:#59c2c5;
	padding-left:20px;
	background:url(../image/)no-repeat;
}

.login-frame .item{
	height:60px;
	margin-buttom:40px;
}

.login-frame .item input{
	line-height:40px;
	width:260px;
	border:none;
	border-bottom: 1px solid #59c2c5;
}

.login-btn{
	display:block;
	height:50px;display:block;
	height:50px;
	color:#fff;
	background:#59c2c5;
	width:265px;
	font-size:16px;
	line-height:30px;
	text-align:center;
	border-radius:10px;
	border:none;
	color:#fff;
	background:#59c2c5;
	width:265px;
	font-size:16px;
	line-height:30px;
	text-align:center;
	border-radius:10px;
	border:none;
}
.login-frame .item1{
	dislpay:flex;
	justify-content: space-between;
	margin-top:1 rem;
}
.login-frame .item1 a{
	line-height:40px;
	font-size:1.1rem;
	margin-top:5 rem;
	padding:1rem 3rem;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95

③注册用户界面()

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link href="css/" type="text/css" rel="stylesheet">
<meta charset="UTF-8">
<script type = "text/javascript" src = "js/jquery-3.6."></script>
	
	<script type = "text/javascript">
	function check()
	{
		var UID = $("#UID").val();
		var upwd = $("#upwd").val();
		var upwd1 = $("#upwd1").val();
		if(upwd != upwd1){
			alert("两次输入的密码不一致,请重新输入!");
			return false;
		}
		
		return true;
	}
	 $(document).ready(function(){
	 });
	</script>
<title>注册账号</title>
</head>
<body>
	<form action = "AddLoginIDServlet" method = "post" onsubmit = "return check()">
	<div class = "content">
		<div class = "box">
		<div class = "item1">
		<h2>用户注册</h2>
		</div>
		<div class = "item">
		<input type = "text" name = "UID" id = "UID" placeholder="账号"/><br/>
		</div>
		<div class = "item">
		<input type = "password" name = "upwd" id = "upwd" placeholder="密码"/><br/>
		</div>
		<div class = "item">
		<input type = "password" name = "upwd1" id = "upwd1" placeholder="确认密码"/><br/>
		</div>
		<input type = "submit" class = "btn" value = "注册"/><br/>
		<a href = "">返回</a>
		<%
		String error4 = (String) ("error4");
		if (error4!= null) {
		if (("addError")) {
			("注册失败!账户名已经存在!");
		} 
	}
	%>
	</div>
	</div>
	</form>
	
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59

④注册用户界面css()

*{margin:0;padding:0;}
html,body
{
	font:12px/150% Arial,Verdana;
}
.content{
	background:url(../image/);
	background-size: cover;
	width:1280px;
	height:559px;
}
.box{
	margin:60px 18% 60px 18%;
	float:right;
	padding:30px;
	background:white;
	background-color:rgba(255,255,255,0.9);
	border-radius:15px;
	
}
.item{
	height:60px;
	margin-buttom:40px;
}
.item input{
	line-height:40px;
	width:260px;
	border:none;
	border-bottom: 1px solid #59c2c5;
	border-radius:3px;
}
.item1{
	font-size:15px;
	height:40px;
}
.btn{
	display:block;
	height:50px;
	color:#fff;
	background:#59c2c5;
	width:265px;
	font-size:16px;
	line-height:30px;
	text-align:center;
	border-radius:10px;
	border:none;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

⑤修改密码界面()

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link href="css/" type="text/css" rel="stylesheet">
<meta charset="UTF-8"><script type = "text/javascript" src = "js/jquery-3.6."></script>
	
	<script type = "text/javascript">
	function check()
	{
		var upwd = $("#upwd").val();
		var upwd1 = $("#upwd1").val();
		var upwd2 = $("#upwd2").val();
		if(upwd1 != upwd2){
			alert("两次输入的密码不一致,请重新输入!");
			return false;
		}
		
		return true;
	}
	 $(document).ready(function(){
	 });
	</script>

<title>更改账号密码</title>
</head>
<body>
	<form action = "UpdateLoginPwdServlet" method = "post" onsubmit = "return check()">
	<div class = "content">
	<div class = "box">
	<div class= "item1"><h2>修改密码</h2></div>
	<div class = item>
	<input type = "text" name = "UID" id = "UID" placeholder="账号"/><br/>
	</div>
	<div class = item>
	<input type = "password" name = "upwd" id = "upwd" placeholder="旧密码"/><br/>
	</div>
	<div class = item>
	<input type = "password" name = "upwd1" id = "upwd1" placeholder="新密码"/><br/>
	</div>
	<div class = item>
	<input type = "password" name = "upwd2" id = "upwd2" placeholder="确认密码"/><br/>
	</div>
	<input type = "submit" class = "btn" value = "提交"/><br/>
	<a href = "">返回</a>
	<%
	String error0 = (String) ("error0");
	if (error0!= null) {
		if (("loginError")) {
			("用户名或密码错误,请重新输入!");
		} else if (("nologinError")) {
			("");
		}
	}
	%>
	</div>
	</div>
	</form>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

⑥注销用户界面()

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link href="css/" type="text/css" rel="stylesheet">
<meta charset="UTF-8">
<title>注销账号</title>
</head>
<body>
	<form action = "DeleteLoginIDServlet" method = "post">
	<div class = "content">
	<div class = "box">
	<div class = "item1">
	<h2>注销账号</h2>
	</div>
	<div class = "item">
	<input type = "text" name = "UID" id = "UID" placeholder="账号"/><br/>
	</div>
	<div class = "item">
	<input type = "password" name = "upwd" id = "upwd" placeholder="密码"/><br/>
	</div>
	<input type = "submit" class = "btn" value = "注销"/><br/>
	<a href = "">返回</a>
	<%
	String error2 = (String) ("error2");
	if (error2!= null) {
	if (("loginError")) {
			("用户名或密码错误!注销失败!");
		}
	}
		%>
	</div>
	</div>

	</form>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

⑦登录成功主界面()

点击学号进入单个学生信息展示界面,可修改学生信息

点击删除删除学生信息

<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<script type = "text/javascript" src = "js/jquery-3.6."></script>
	
	<script type = "text/javascript">
	 $(document).ready(function(){
	 	$("tr:odd").css("background-color","lightgrey");
	 
	 });
	</script>
	
<link href="css/" type="text/css" rel="stylesheet">
<meta charset="UTF-8">
<title>学生信息列表</title>
</head>
<body>

	<div class = "content">
	<div class = "box">
	<table  border="2" cellspacing="0">
		<tr>
			<th><h2>学号</h2></th>
			<th><h2>姓名</h2></th>
			<th><h2>年龄</h2></th>
			<th><h2>专业</h2></th>
			<th><h2>操作</h2></th>
		</tr>
		<%
		Page page1 = (Page)("page1");
		
		for(Student student:()){
			%>
			<tr>
				<td><a href = "QueryStudentBySnoServlet?sno=<%=()%>"><%=() %></a></td>
				<td><%=() %></td>
				<td><%=() %></td>
				<td><%=() %></td>
				<td><a href = "DeleteStudentServlet?sno=<%=() %>">删除</a></td>
			</tr>
			<%			
		}
		%>
		</table>
		<div class = item>
		<a href = "">增加学生</a>
		</div>
	<% 
		if(()==()-1){
		%>
		<div class = item>
		<a href = "QueryStudentByPageServlet?currentPage=0">首页</a>
		<a href = "QueryStudentByPageServlet?currentPage=<%=()-1%>">上一页</a>
		</div>
		<% 
		}
		else if(()==0){
			%>
			<div class = item>
			<a href = "QueryStudentByPageServlet?currentPage=<%=()+1%>">下一页</a>
			<a href = "QueryStudentByPageServlet?currentPage=<%=()-1%>">尾页</a>
			</div>
			<%
		}
		else{
			%>
			<div class = item>
			<a href = "QueryStudentByPageServlet?currentPage=0">首页</a>
			<a href = "QueryStudentByPageServlet?currentPage=<%=()-1%>">上一页</a>
			<a href = "QueryStudentByPageServlet?currentPage=<%=()+1%>">下一页</a>
			<a href = "QueryStudentByPageServlet?currentPage=<%=()-1%>">尾页</a>
			</div>
			<%
		}
		%>
		<input type = "button" value = "上传作业" class = "btn"  onclick = "location = ''"/><br/>
			<%
	String error = (String)("error");
	if(error!=null){
	if(("addError")){
		("增加失败!");
	}
	else if(("noaddError")){
		("增加成功!");
	}
	}
	
	String error1 = (String)("error1");
	if(error1!=null){
	if(("deleteError")){
		("删除失败!");
	}
	else if(("nodeleteError")){
		("删除成功!");
	}
	}
	String error2 = (String)("error2");
	if(error2!=null){
	if(("updateError")){
		("修改失败!");
	}
	else if(("noupdateError")){
		("修改成功!");
	}
	}
	
	
	String error3 = (String)("error3");
	if(error3!=null){
	if(("uploadError")){
		("上传失败!");
	}
	else if(("nouploadError")){
		("上传成功!");
	}
	}
	%>
		</div>
		</div>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126

⑧登陆成功界面css()

*{margin:0;padding:0;}
html,body
{
	font:12px/150% Arial,Verdana;
}
.content{
	background:url(../image/);
	background-size: cover;
	width:1280px;
	height:559px;
}
.box{
	margin:60px 18% 60px 18%;
	float:right;
	padding:30px;
	background:white;
	background-color:rgba(255,255,255,0.9);
	border-radius:15px;
	
}
.item{
	height:40px;
	
	border-radius:15px;
}
.item a{
	background-color: lightgrey;
	text-decoration: none;
	font-size:15px;
	color:black;
	border-radius:3px;
}
.item1{
	font-size:15px;
	height:40px;
}
table{
	width:100%;
	border-collapse:collapse;
}
table body{
	diaplay:block;
	height:300px;
	overflow-y: scroll;
}
table td{
	border:1px solid #A6A6A6;
	height:60px;
	width:300px;
	text-align: center;
	font-size: 15px;
}
table th{
	height:60px;
	border:1px solid #A6A6A6;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56

⑨点击学号,修改学生信息界面()

<%@page import=""%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="css/" type="text/css" rel="stylesheet">
<title>修改学生信息</title>
</head>
<body>
	<%
		Student student = (Student)("student");
	%>		
	<form action = "UpdateStudentServlet" method = "post">
	<div class = "content">
	<div class = "box">
	<div class = "item1">
	<h2>修改学生信息</h2>
	</div>
		<div class = "item">
		学号:<input type = "text" name = "sno" value ="<%=()%>" readonly = "readonly"/><br/>
		</div>
		<div class = "item">
		姓名:<input type = "text" name = "name" value ="<%=()%>"/><br/>
		</div>
		<div class = "item">
		年龄:<input type = "text" name = "age" value ="<%=()%>"/><br/>
		</div>
		<div class = "item">
		专业:<input type = "text" name = "dept" value ="<%=()%>"/><br/>
		</div>
		<input type = "submit" class = "btn" value = "修改"/>
		<a href = "QueryStudentByPageServlet">返回</a>
		</div>
		</div>
	</form>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

⑩增加学生信息()

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="css/" type="text/css" rel="stylesheet">
<script type = "text/javascript" src = "js/jquery-3.6."></script>
	
	<script type = "text/javascript">
	function check()
	{
		var sname = $("#sname").val();
		var sno = $("#sno").val();
		var sage = $("#sage").val();
		var sdept = $("#sdept").val();
		if(!(sno>1&&sno<2000)){
			alert("学号有误!必须是1-2000");
			return false;
		}
		if(!(>1&&<5)){
			alert("姓名有误!必须是2-4位");
			return false;
		}
		if(!(sage>1&&sage<100)){
			alert("年龄有误!必须是1-100");
			return false;
		}
		return true;
	}
	 $(document).ready(function(){
	 });
	</script>
	
<title>增加学生信息</title>
</head>
<body>
	<form action = "AddStudentServlet" method = "post"  onsubmit = "return check()">
	<div class = "content">
	<div class = "box">
	<div class = "item2">
	<h2>增加学生信息</h2>
	</div>
	<div class = "item">
	<input type = "text" name = "name" id = "sname" placeholder="姓名"/><br/>
	</div>
	<div class = "item">
	<input type = "text" name = "sno" id = "sno" placeholder="学号"/><br/>
	</div>
	<div class = "item">
	<input type = "text" name = "age" id = "sage" placeholder="年龄"/><br/>
	</div>
	<div class = "item">
	<input type = "text" name = "dept" id = "sdept" placeholder="专业"/><br/>
	</div>
	<input type = "submit" class = "btn" value = "增加"/><br/>
	<a href = "QueryStudentByPageServlet">返回</a>
	</div>
	</div>
	</form>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62

上传作业操作()

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="css/" type="text/css" rel="stylesheet">
<title>上传作业</title>
</head>
<body>
	<form action ="UploadServlet" method = "post" enctype = "multipart/form-data">
	<div class = "content">
	<div class = "box">
	<div class = "item2">
	<h2>上传作业</h2>
	</div>
	<div class = "item">
	<input type = "text" name="sno" placeholder="学号"/><br/>
	</div>
	<div class = "item">
	<input type = "text" name = "name" placeholder="姓名"/><br/>
	</div>
	<input type = "file" name = "spiature"/>
	<br/>
	<br/>
	<input type = "submit" class = "btn" value ="上传"/>
	<a href = "QueryStudentByPageServlet">返回</a>
	</div>
	</div>
	</form>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

2.三层架构

①表示层Servlet

检查登录的用户名和密码是否匹配()

package ;

import ;
import ;
import ;
import ;
import ;

import ;
import ;


public class CheckLoginServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		("utf-8");
		String ID = ("UID");
		String pwd = ("upwd");
		IStudentService service = new StudentServiceImpl();
		boolean result = (ID,pwd);
		("text/html;charest=UTF-8");
		("utf-8");
		if(!result) {
			("error", "loginError");
		}else {
			("error", "nologinError");
		}
		("").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

注册账户表示层()

package ;

import ;
import ;
import ;
import ;
import ;

import ;
import ;

/**
 * Servlet implementation class AddLoginIDServlet
 */
public class AddLoginIDServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		("utf-8");
		String ID = ("UID");
		String pwd = ("upwd");
		IStudentService studentService = new StudentServiceImpl();
		boolean result = (ID,pwd);
		
		("text/html;charest=UTF-8");
		("utf-8");
		if(!result) {
			("error4", "addError");
			("").forward(request, response);
		}else {
			("error4", "noaddError");
			("").forward(request, response);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

修改密码表示层()

package ;

import ;
import ;
import ;
import ;
import ;

import ;
import ;

/**
 * Servlet implementation class UpdateLoginPwdServlet
 */
public class UpdateLoginPwdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		("utf-8");
		String ID = ("UID");
		String pwd = ("upwd");
		String pwd1 = ("upwd1");
		IStudentService service = new StudentServiceImpl();
		boolean result = (ID,pwd);
		("text/html;charest=UTF-8");
		("utf-8");
		if(!result) {
			("error0", "loginError");
			("").forward(request, response);
		}else {
			("error0", "nologinError");
			boolean result1 = (ID,pwd1);
			if(!result1) {
				("").forward(request, response);
			}else {
				("error1", "noupdateError");
				("").forward(request, response);
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

注销用户表示层()

package ;

import ;
import ;
import ;
import ;
import ;

import ;
import ;

/**
 * Servlet implementation class DeleteLoginIDServlet
 */
public class DeleteLoginIDServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		("utf-8");
		String ID = ("UID");
		String pwd = ("upwd");
		IStudentService service = new StudentServiceImpl();
		boolean result = (ID,pwd);
		boolean result1 = (ID);
		("text/html;charest=UTF-8");
		("utf-8");
		if(!result) {
			("error2", "loginError");
			("").forward(request, response);
		}else {
			("error2", "nologinError");
			if(!result1) {
				("error3", "deleteError");
				("").forward(request, response);
			}else {
				("error3", "nodeleteError");
				("").forward(request, response);
		}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

分页显示()

package ;

import ;
import ;

import ;
import ;
import ;
import ;

import ;
import ;
import ;
import ;

public class QueryStudentByPageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public QueryStudentByPageServlet() {
        super();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		IStudentService studentService = new StudentServiceImpl();
		int count = ();
		
		Page page = new Page();
		
		
		String cPage = ("currentPage");
		
		if(cPage == null) {
			cPage = "0";
		}
		int currentPage = (cPage);
		(currentPage);

		int totalCount = ();
		(totalCount);
		int pageSize = 4;
		
		(pageSize);
		
		List<Student> students = (currentPage, pageSize);
		
		(students);
		("page1", page);
		("").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

按学号查询学生信息()

package ;

import ;
import ;
import ;
import ;
import ;

import ;
import ;
import ;

public class QueryStudentBySnoServlet extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	("UTF-8");
	int sno = (("sno"));
	IStudentService service = new StudentServiceImpl();
	Student student = (sno);
	("student", student);//将查询到的request信息放在request域中
	("").forward(request,response);
	}

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

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

增加学生信息()

package ;

import ;

import ;
import ;
import ;
import ;

import ;
import ;
import ;

public class AddStudentServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		("utf-8");
		String name = ("name");
		int sno = (("sno"));
		int age = (("age"));
		String dept = ("dept");
		Student student = new Student(name, sno, age, dept);
		
		IStudentService studentService = new StudentServiceImpl();
		boolean result = (student);
		
		("text/html;charest=UTF-8");
		("utf-8");
		if(!result) {
			("error", "addError");
		}else {
			("error", "noaddError");
		}
		("QueryStudentByPageServlet").forward(request, response);
	}

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

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

删除学生信息()

package ;

import ;
import ;
import ;
import ;
import ;

import ;
import ;

/**
 * Servlet implementation class DeleteStudentServlet
 */
public class DeleteStudentServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		("utf-8");
		int sno = (("sno"));
		IStudentService service = new StudentServiceImpl();
		boolean result = (sno);
		("text/html;charest=UTF-8");
		("utf-8");
		if(!result) {
			("error1", "deleteError");
		}else {
			("error1", "nodeleteError");
		}
		("QueryStudentByPageServlet").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

修改学生信息表示层()

package ;

import ;
import ;
import ;
import ;
import ;

import ;
import ;
import ;

public class UpdateStudentServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		("UTF-8");
		String name = ("name");
		int sno = (("sno"));
		int age = (("age"));
		String dept = ("dept");
		Student student = new Student(name, age, dept);
		
		(sno);
		
		IStudentService service = new StudentServiceImpl();
		boolean result = (sno, student);
		
		("text/html;charest=UTF-8");
		("utf-8");
		if(!result) {
			("error2", "updateError");
		}else {
			("error2", "noupdateError");
		}

		("QueryStudentByPageServlet").forward(request, response);
	}
		

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

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

上传作业()

package ;

import ;
import ;
import ;
import ;

import ;
import ;
import ;
import ;

import ;
import ;
import ;
import ;
import ;

import ;
import ;


public class UploadServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		("UTF-8");
		("UTF-8");
		("text/html; charset=UTF-8");
		String name = null;
		int sno = -1;
		
		boolean isMutipart = (request);
		if(isMutipart) {
			DiskFileItemFactory factory = new DiskFileItemFactory();
			ServletFileUpload upload = new ServletFileUpload(factory);
			(new File("D:\uploadtemp"));
			List<FileItem> items = null;
				try {
					items = (request);
				} catch (FileUploadException e) {
					// TODO Auto-generated catch block
					();
				}
			Iterator<FileItem> iter = ();
			while(()) {
				FileItem item= ();
				String fileName = ();
				String itemName = ();
				if(()) {
					if(("name")){
						name = ("utf-8");
					}else if(("sno")) {
						sno =(("utf-8"));
					}else {
						
					}
				}else {
					//定义上传路径:指定上传的位置
					String path = "D:\upload";
					File file = new File(path,fileName);
						try {
							(file);
							} catch (Exception e) {
							();
							}
			}
		}
		IStudentService studentService = new StudentServiceImpl();
		boolean result = (sno,name);
		
		(name+sno);
		(result);
		if(!result) {
			("error3", "uploadError");
			("QueryStudentByPageServlet").forward(request, response);
			
		}else{
			("error3", "nouploadError");
			("QueryStudentByPageServlet").forward(request, response);
			
		}
		}
	}


	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93

②业务逻辑层Service

Service接口()

package ;

import ;

import ;

public interface IStudentService {
	//查询全部学生信息
	public List<Student> queryAllStudents();
	//按照学号查询学生信息
	public Student queryStudentBySno(int sno);
	//删除学生信息
	public boolean deleteStudentBySno(int sno) ;
	
	//更改学生信息
	public boolean updateStudentBySno(int sno, Student student) ;
	
	//增加学生信息
	public boolean addStudent(Student student) ;
	
	//查询总数据
	public int getTotalCount();
	//分页
	public List<Student> queryStudentsByPage(int current, int pageSize);
	//检查登陆账户和密码
	public boolean checkLoginID(String ID,String pwd);
	//注册账户
	public boolean addLoginID(String ID, String pwd);
	//更改密码
	public boolean updateLoginPwd(String ID,String pwd1);
	//注销账号
	public boolean deleteLoginID(String ID);
	//判断ID是否存在
	public boolean IDExist(String ID);
	//判断上传作业输入的学生信息是否存在
	public boolean upLoadWork(int sno, String name);

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

接口的实现类()

package ;

import ;

import ;
import ;
import ;
import ;
import ;

//业务逻辑层:逻辑性的增删改查(增:查+增),对dao层进行的组装
public class StudentServiceImpl implements IStudentService{
	IStudentDao studentDao = new StudentDaoImpl();
	//查询全部学生信息
	public List<Student> queryAllStudents(){
		return ();
	}
	//按照学号查询学生信息
	public Student queryStudentBySno(int sno) {
		return (sno);
		
	}
	//删除学生信息
	public boolean deleteStudentBySno(int sno) {
		if((sno)) {
			return (sno);
		}
			return false;
	}
	
	
	//更改学生信息
	public boolean updateStudentBySno(int sno, Student student) {
			return (sno, student);
	}
	
	
	//增加学生信息
	public boolean addStudent(Student student) {
		if(!(())) {
			(student);
			return true;
		}else {
			("学号重复!");
			return false;
		}
	}
	
	//查询总条数
	@Override
	public int getTotalCount() {
		return ();
	}
	//查询当前页的数据集合
	@Override
	public List<Student> queryStudentsByPage(int current, int pageSize) {
		return (current, pageSize);
	}
	
	
	@Override
	public boolean checkLoginID(String ID, String pwd) {
		return (ID, pwd);
	}
	@Override
	public boolean addLoginID(String ID, String pwd) {
		return (ID,pwd);
					
	}
	@Override
	public boolean updateLoginPwd(String ID, String pwd1) {
		return (ID,pwd1);
	}
	@Override
	public boolean deleteLoginID(String ID) {
		return (ID);
	}
	@Override
	public boolean IDExist(String ID) {
		return (ID);
	}
	@Override
	public boolean upLoadWork(int sno, String name) {
		return (sno,name);
	}
	
	
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

③数据访问层Dao

接口()

package ;

import ;

import ;

public interface IStudentDao {
	public boolean updateLoginPwd(String ID,String pwd1);


	//查询全部学生信息
	public List<Student> queryAllStudents();
	
	
	//判断此人是否存在
	public boolean isExist(int sno) ;
	
	//增加学生信息
	public boolean addStudent(Student student);
	//删除学生信息
	public boolean deleteStudentBySno(int sno);
	
	//根据sno找到要修改的学生,然后再进行修改
	public boolean  updateStudentBySno(int sno,Student student);
	//根据学号查询学生信息
	public Student queryStudentBySno(int sno);
	
	//查询总数据数
	public int getTotalCount();
	//currentPage:当前页(页码)pageSize:页面大小(每页显示的数据条数)
	public List<Student> queryStudentByPage(int currentPage,int pageSize);
	
	public boolean checkLoginID(String ID,String pwd);


	public boolean addLoginID(String ID, String pwd);


	public boolean deleteLoginID(String ID);


	public boolean IDExist(String ID);


	public boolean upLoadWork(int sno, String name);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

接口的实现类()

package ;

import ;
import ;
import ;
import ;
import ;
import ;
import ;

import ;
import ;
import ;

public class StudentDaoImpl implements IStudentDao{
	
	private final String URL = "jdbc:mysql://localhost:3306/STUDENT?useSSL=false&serverTimezone=UTC";
	private final String UserName = "root";
	private final String Pwd = "123456";

	String JDBC_DRIVER = "";
	//查询全部学生信息
	public List<Student> queryAllStudents(){
		PreparedStatement pstmt = null;
		Student student = null;
		List<Student> students = new ArrayList<>();
		ResultSet rs = null;
		try {
			String sql = "select * from student1";
			rs = (sql, null);
			while(()) {
				int sno= ("sno");
				String name = ("name");
				int age = ("age");
				String dept = ("dept");
				student = new Student(name, sno, age, dept);
				(student);
			}
			return students;
			
		} catch(Exception e) {
			();
			return null;
		}
		finally {
			(rs, pstmt, );
	}
	}
	
	
	//判断此人是否存在
	public boolean isExist(int sno) {
		return queryStudentBySno(sno) == null? false:true;
	}
	
	//增加学生信息
	public boolean addStudent(Student student) {
		String sql = "insert into student1(name,sno,age,dept) values(?,?,?,?)";
		Object[] params = {(),(),(),()};
		return (sql, params);
	}
	//删除学生信息
	public boolean deleteStudentBySno(int sno) {
		String sql = "delete from student1 where sno =?";
		Object[] params = {sno};
		return (sql, params);
	}
	
	//根据sno找到要修改的学生,然后再进行修改
	public boolean  updateStudentBySno(int sno,Student student) {
		String sql = "update student1 set name =?,age=?,dept=? where sno=?";
		Object[] params = {(),(),(),sno};
		
		return (sql, params);
		
	}
	//根据学号查询学生信息
	public Student queryStudentBySno(int sno){
		PreparedStatement pstmt = null;
		Student student = null;
		Connection connection = null;
		ResultSet rs = null;
		try {
			(JDBC_DRIVER);
			connection = (URL,UserName,Pwd);
			String sql = "select * from student1 where sno = ?";
			pstmt = (sql);
			(1, sno);
			rs = ();
			if(()) {
				int no= ("sno");
				String name = ("name");
				int age = ("age");
				String dept = ("dept");
				student = new Student(name, no, age, dept);
			}
			return student;
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			();
			return null;
		} catch(SQLException e) {
			();
			return null;
		}catch(Exception e) {
			();
			return null;
		}
		finally {
			(rs, pstmt, );
				}

	}


	@Override
	public int getTotalCount() {//查询总数据数
		String sql = "select count(1) from student1";
		return (sql);
	}


	@Override
	public List<Student> queryStudentByPage(int currentPage, int pageSize) {
		String sql = "select * from student1 order by sno asc limit ?,?";
		Object[] params = {currentPage*pageSize,pageSize};
		
		List<Student> students = new ArrayList<>();
		ResultSet rs = (sql, params);
		try {
			while(()) {
				Student student = new Student(("name"),("sno"),("age"),("dept"));
				(student);
			}
		} catch (SQLException e) {
			();
		}catch (Exception e) {
			();
		}
		return students;
	}


	@Override
	public boolean checkLoginID(String ID, String pwd){
		int count = 0;
		String sql = "select * from login where ID=? and pwd=?";
		Object[] params = {ID,pwd};
		ResultSet rs = (sql, params);
		try {
			while(()) {
				count++;
			}
			if(count>0)
				return true;
			else
				return false;
		} catch (SQLException e) {
			();
			}
				return false;
	}


	@Override
	public boolean addLoginID(String ID, String pwd) {
		// TODO Auto-generated method stub
		String sql = "insert into login(ID,pwd) values(?,?)";
		Object[] params = {ID,pwd};
		return (sql, params);
	}


	@Override
	public boolean updateLoginPwd(String ID, String pwd1) {
		String sql = "update login set pwd =? where ID=?";
		Object[] params = {pwd1,ID};
		return (sql, params);
	}


	@Override
	public boolean deleteLoginID(String ID) {
		String sql = "delete from login where ID =?";
		Object[] params = {ID};
		return (sql, params);
	}


	@Override
	public boolean IDExist(String ID) {
		String sql = "select *from login where ID = ?";
				Object[] params = {ID};
		return (sql, params);
	}


	@Override
	public boolean upLoadWork(int sno, String name) {
		int count = 0;
		String sql = "select *from student1 where sno = ? and name = ?";
		Object[] params = {sno,name};
		ResultSet rs = (sql, params);
		try {
			while(()) {
				count++;
			}
			if(count>0)
				return true;
			else
				return false;
		} catch (SQLException e) {
			();
			}
				return false;
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218

④通用的数据库操作(DBUtils.java)

package ;

import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;

import ;

//通用的数据库操作方法
public class DBUtil {
	private static final String URL = "jdbc:mysql://localhost:3306/STUDENT?useSSL=false&serverTimezone=UTC";
	private static final String UserName = "root";
	private static final String Pwd = "123456";
	private static final String JDBC_DRIVER = "";
	public static Connection connection = null;
	public static PreparedStatement pstmt = null;
	public static ResultSet rs = null;
	
	//查询总数
	public static int getTotalCount(String sql){
		int count = -1;
		try {
			pstmt = createPreParedStatement(sql,null);
			rs = ();
			if(()) {
				count = (1);
			}
		} catch (SQLException e) {
			();
		}catch (Exception e) {
			();
		}finally {
			closeAll(rs,pstmt,connection);
		}
		return count;
	}
	
	//增删改
	public static boolean executeUpdate(String sql,Object[] params) {
		try {
			pstmt = createPreParedStatement(sql,params);
			int count = ();
			
			(count);
			if(count>0) {
				return true;
			}
			else {
				return false;
			}
		} catch (ClassNotFoundException e) {
			();
			return false;
		} catch(SQLException e) {
			();
			return false;
		}catch(Exception e) {
			();
			return false;
		}
		finally {
			closeAll(null,pstmt,connection);
	}
	}
	public static void closeAll(ResultSet rs,Statement stmt,Connection connection){
		try{
			if(rs!=null)();
			if(pstmt!=null)();
			if(connection!=null)();
		
		}catch(SQLException e) {
			();
		}
	}
	
	public static PreparedStatement createPreParedStatement(String sql,Object[] params) throws ClassNotFoundException, SQLException {
			pstmt = getConnection().prepareStatement(sql);
			if(params!=null) {
			for(int i = 0;i<;i++) {
				(i+1, params[i]);
			}
			}
			return pstmt;
	}
	
	public static Connection getConnection() throws ClassNotFoundException, SQLException {
		(JDBC_DRIVER);
		return (URL,UserName,Pwd);
	}
	//通用的查
	public static ResultSet executeQuery(String sql,Object[] params){
		List<Student> students = new ArrayList<>();
		Student student = null;
		
		try {
			pstmt = createPreParedStatement(sql,params);
			rs = ();
			
			return rs;
			
		} catch(SQLException e) {
			();
			return null;
		}catch(Exception e) {
			();
			return null;
		}
		
	}

	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116

封装数据

①分页帮助类()

package ;

import ;

//分页帮助类
public class Page {
	private int currentPage;
	private int pageSize;
	private int totalCount;
	private int totalPage;
	private List<Student> students;
	public Page() {
		
	}
	public Page(int currentPage, int pageSize, int totalCount, int totalPage, List<Student> students) {
		 = currentPage;
		 = pageSize;
		 = totalCount;
		 = totalPage;
		 = students;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		 = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	
	public void setPageSize(int pageSize) {
		 = pageSize;
		 = %==0?/:/+1;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		 = totalCount;
	}
	public int getTotalPage() {
		return totalPage;
	}
	
	
	public List<Student> getStudents() {
		return students;
	}
	public void setStudents(List<Student> students) {
		 = students;
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53

②封装学生信息()

package ;

public class Student {
	private String name;
	private int sno;
	private int age;
	private String dept;
	
	public Student(int sno) {
		 = sno;
	}
	
	public Student() {
		
	}
	public Student(String name, int age, String dept) {
		 = name;
		 = age;
		 = dept;
	}
	public Student(String name, int sno, int age, String dept) {
		 = name;
		 = sno;
		 = age;
		 = dept;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		 = name;
	}
	public int getSno() {
		return sno;
	}
	public void setSno(int sno) {
		 = sno;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		 = age;
	}
	public String getDept() {
		return dept;
	}
	public void setDept(String dept) {
		 = dept;
	}
	public String toString() {
		return ()+"-"+()+"-"+()+"-"+();
		
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56

4.项目所需jar包

项目需要3个jar包,前两个jar包属于文件上传所需,最后一个为连接数据库的jar包

下载官网地址:/

五.数据库表格

本人用的是mysql数据库,直接在mysql数据库中新建表格

登录注册表格login

②学生信息表格student1

最后

深知大多数初中级Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

小编已加密:aHR0cHM6Ly9kb2NzLnFxLmNvbS9kb2MvRFVrVm9aSGxQZUVsTlkwUnc==出于安全原因,我们把网站通过base64编码了,大家可以通过base64解码把网址获取下来。