国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Javaweb學(xué)生信息管理系統(tǒng)(Mysql+JSP+MVC+CSS)

這篇具有很好參考價(jià)值的文章主要介紹了Javaweb學(xué)生信息管理系統(tǒng)(Mysql+JSP+MVC+CSS)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

項(xiàng)目源碼及數(shù)據(jù)庫(kù):

鏈接:https://pan.baidu.com/s/1ktUyxbOI9lljWr-HRTRIiQ?pwd=1024
提取碼:1024

?

目錄

一.項(xiàng)目介紹

二.運(yùn)行效果

1.登錄界面

2.主界面(點(diǎn)擊學(xué)號(hào)修改學(xué)生信息)

3.增加學(xué)生界面

?編輯

三.項(xiàng)目目錄結(jié)構(gòu)

?四.代碼展示

1.jsp及css代碼

?①登錄界面代碼(login.jsp)

②登錄界面css(login.css)

③注冊(cè)用戶界面(register.jsp)

④注冊(cè)用戶界面css(index.css)

⑤修改密碼界面(UpdateLoginID.jsp)

⑥注銷(xiāo)用戶界面(DeleteLoginID.jsp)

⑦登錄成功主界面(index.jsp)

⑧登陸成功界面css(show.css)

⑨點(diǎn)擊學(xué)號(hào),修改學(xué)生信息界面(StudentInfo.jsp)

⑩增加學(xué)生信息(add.jsp)

?上傳作業(yè)操作(UpAndDown.jsp)

2.三層架構(gòu)

①表示層Servlet

②業(yè)務(wù)邏輯層Service

③數(shù)據(jù)訪問(wèn)層Dao

④通用的數(shù)據(jù)庫(kù)操作(DBUtils.java)

3.JavaBean封裝數(shù)據(jù)

①分頁(yè)幫助類(lèi)(Page.java)

②封裝學(xué)生信息(Student.java)

4.項(xiàng)目所需jar包

五.數(shù)據(jù)庫(kù)表格

①登錄注冊(cè)表格login

②學(xué)生信息表格student1


一.項(xiàng)目介紹

本系統(tǒng)主要實(shí)現(xiàn)對(duì)基于Javaweb學(xué)生信息管理系統(tǒng)所需的各項(xiàng)基本功能,能夠?qū)W(xué)生信息進(jìn)行增刪改查等功能,并可以實(shí)現(xiàn)用戶注冊(cè)、用戶登陸等功能。

數(shù)據(jù)庫(kù):Mysql

開(kāi)發(fā)工具:Eclipse

開(kāi)發(fā)環(huán)境:JDK+Tomcat

二.運(yùn)行效果

1.登錄界面

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

2.主界面(點(diǎn)擊學(xué)號(hào)修改學(xué)生信息)

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

3.增加學(xué)生界面

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

三.項(xiàng)目目錄結(jié)構(gòu)

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

?四.代碼展示

1.jsp及css代碼

?①登錄界面代碼(login.jsp)

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

<title>學(xué)生信息管理系統(tǒng)-登錄界面</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="register.jsp"> 立即注冊(cè)</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="UpdateLoginPwd.jsp"> 修改密碼</a> 
							<a	href="DeleteLoginID.jsp"> 注銷(xiāo)用戶</a>
						</div>
						<%
							String error = (String) request.getAttribute("error");
							String error0 = (String) request.getAttribute("error0");
							String error1 = (String) request.getAttribute("error1");
							String error2 = (String) request.getAttribute("error2");
							String error3 = (String) request.getAttribute("error3");
							String error4 = (String) request.getAttribute("error4");

							if (error != null) {
								if (error.equals("loginError")) {
									out.println("用戶名或密碼錯(cuò)誤!登錄失?。?);
								} else if (error.equals("nologinError")) {
									response.sendRedirect("QueryStudentByPageServlet");
								}
							}

							if (error0 != null) {
								if (error0.equals("loginError")) {
									out.println("用戶名或密碼錯(cuò)誤!修改失??!");
								} else if (error0.equals("nologinError")) {
									if (error1 != null) {
								if (error1.equals("noupdateError")) {
									out.println("密碼修改成功!");
								}
									}
								}
							}
							if (error2 != null) {
								if (error2.equals("loginError")) {
									out.println("用戶名或密碼錯(cuò)誤!注銷(xiāo)失??!");
								} else if (error2.equals("nologinError")) {
									if (error3 != null) {
								if (error3.equals("nodeleteError")) {
									out.println("賬戶注銷(xiāo)成功!");
								}
									}
								}
							}
							if (error4 != null) {
								if (error4.equals("noaddError")) {
									out.println("賬戶注冊(cè)成功!");
								}
							}
							%>
						</div>
					</div>
				</div>
			</div>
	</form>

</body>



</html>

②登錄界面css(login.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/login.jpg);
	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/icon5.jpg)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;
}

③注冊(cè)用戶界面(register.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link href="css/index.css" type="text/css" rel="stylesheet">
<meta charset="UTF-8">
<script type = "text/javascript" src = "js/jquery-3.6.0.js"></script>
	
	<script type = "text/javascript">
	function check()
	{
		var UID = $("#UID").val();
		var upwd = $("#upwd").val();
		var upwd1 = $("#upwd1").val();
		if(upwd != upwd1){
			alert("兩次輸入的密碼不一致,請(qǐng)重新輸入!");
			return false;
		}
		
		return true;
	}
	 $(document).ready(function(){
	 });
	</script>
<title>注冊(cè)賬號(hào)</title>
</head>
<body>
	<form action = "AddLoginIDServlet" method = "post" onsubmit = "return check()">
	<div class = "content">
		<div class = "box">
		<div class = "item1">
		<h2>用戶注冊(cè)</h2>
		</div>
		<div class = "item">
		<input type = "text" name = "UID" id = "UID" placeholder="賬號(hào)"/><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="確認(rèn)密碼"/><br/>
		</div>
		<input type = "submit" class = "btn" value = "注冊(cè)"/><br/>
		<a href = "login.jsp">返回</a>
		<%
		String error4 = (String) request.getAttribute("error4");
		if (error4!= null) {
		if (error4.equals("addError")) {
			out.println("注冊(cè)失??!賬戶名已經(jīng)存在!");
		} 
	}
	%>
	</div>
	</div>
	</form>
	
</body>
</html>

④注冊(cè)用戶界面css(index.css)

*{margin:0;padding:0;}
html,body
{
	font:12px/150% Arial,Verdana;
}
.content{
	background:url(../image/login.jpg);
	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;
}

⑤修改密碼界面(UpdateLoginID.jsp)

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

<title>更改賬號(hào)密碼</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="賬號(hào)"/><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="確認(rèn)密碼"/><br/>
	</div>
	<input type = "submit" class = "btn" value = "提交"/><br/>
	<a href = "login.jsp">返回</a>
	<%
	String error0 = (String) request.getAttribute("error0");
	if (error0!= null) {
		if (error0.equals("loginError")) {
			out.println("用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!");
		} else if (error0.equals("nologinError")) {
			response.sendRedirect("login.jsp");
		}
	}
	%>
	</div>
	</div>
	</form>
</body>
</html>

⑥注銷(xiāo)用戶界面(DeleteLoginID.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link href="css/index.css" type="text/css" rel="stylesheet">
<meta charset="UTF-8">
<title>注銷(xiāo)賬號(hào)</title>
</head>
<body>
	<form action = "DeleteLoginIDServlet" method = "post">
	<div class = "content">
	<div class = "box">
	<div class = "item1">
	<h2>注銷(xiāo)賬號(hào)</h2>
	</div>
	<div class = "item">
	<input type = "text" name = "UID" id = "UID" placeholder="賬號(hào)"/><br/>
	</div>
	<div class = "item">
	<input type = "password" name = "upwd" id = "upwd" placeholder="密碼"/><br/>
	</div>
	<input type = "submit" class = "btn" value = "注銷(xiāo)"/><br/>
	<a href = "login.jsp">返回</a>
	<%
	String error2 = (String) request.getAttribute("error2");
	if (error2!= null) {
	if (error2.equals("loginError")) {
			out.println("用戶名或密碼錯(cuò)誤!注銷(xiāo)失??!");
		}
	}
		%>
	</div>
	</div>

	</form>
</body>
</html>

⑦登錄成功主界面(index.jsp)

點(diǎn)擊學(xué)號(hào)進(jìn)入單個(gè)學(xué)生信息展示界面,可修改學(xué)生信息

點(diǎn)擊刪除刪除學(xué)生信息

<%@page import="student.entity.Page"%>
<%@page import="java.util.List"%>
<%@page import="student.entity.Student"%>
<%@ 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.0.js"></script>
	
	<script type = "text/javascript">
	 $(document).ready(function(){
	 	$("tr:odd").css("background-color","lightgrey");
	 
	 });
	</script>
	
<link href="css/show.css" type="text/css" rel="stylesheet">
<meta charset="UTF-8">
<title>學(xué)生信息列表</title>
</head>
<body>

	<div class = "content">
	<div class = "box">
	<table  border="2" cellspacing="0">
		<tr>
			<th><h2>學(xué)號(hào)</h2></th>
			<th><h2>姓名</h2></th>
			<th><h2>年齡</h2></th>
			<th><h2>專(zhuān)業(yè)</h2></th>
			<th><h2>操作</h2></th>
		</tr>
		<%
		Page page1 = (Page)request.getAttribute("page1");
		
		for(Student student:page1.getStudents()){
			%>
			<tr>
				<td><a href = "QueryStudentBySnoServlet?sno=<%=student.getSno()%>"><%=student.getSno() %></a></td>
				<td><%=student.getName() %></td>
				<td><%=student.getAge() %></td>
				<td><%=student.getDept() %></td>
				<td><a href = "DeleteStudentServlet?sno=<%=student.getSno() %>">刪除</a></td>
			</tr>
			<%			
		}
		%>
		</table>
		<div class = item>
		<a href = "add.jsp">增加學(xué)生</a>
		</div>
	<% 
		if(page1.getCurrentPage()==page1.getTotalPage()-1){
		%>
		<div class = item>
		<a href = "QueryStudentByPageServlet?currentPage=0">首頁(yè)</a>
		<a href = "QueryStudentByPageServlet?currentPage=<%=page1.getCurrentPage()-1%>">上一頁(yè)</a>
		</div>
		<% 
		}
		else if(page1.getCurrentPage()==0){
			%>
			<div class = item>
			<a href = "QueryStudentByPageServlet?currentPage=<%=page1.getCurrentPage()+1%>">下一頁(yè)</a>
			<a href = "QueryStudentByPageServlet?currentPage=<%=page1.getTotalPage()-1%>">尾頁(yè)</a>
			</div>
			<%
		}
		else{
			%>
			<div class = item>
			<a href = "QueryStudentByPageServlet?currentPage=0">首頁(yè)</a>
			<a href = "QueryStudentByPageServlet?currentPage=<%=page1.getCurrentPage()-1%>">上一頁(yè)</a>
			<a href = "QueryStudentByPageServlet?currentPage=<%=page1.getCurrentPage()+1%>">下一頁(yè)</a>
			<a href = "QueryStudentByPageServlet?currentPage=<%=page1.getTotalPage()-1%>">尾頁(yè)</a>
			</div>
			<%
		}
		%>
		<input type = "button" value = "上傳作業(yè)" class = "btn"  onclick = "location = 'UpAndDown.jsp'"/><br/>
			<%
	String error = (String)request.getAttribute("error");
	if(error!=null){
	if(error.equals("addError")){
		out.println("增加失??!");
	}
	else if(error.equals("noaddError")){
		out.println("增加成功!");
	}
	}
	
	String error1 = (String)request.getAttribute("error1");
	if(error1!=null){
	if(error1.equals("deleteError")){
		out.println("刪除失??!");
	}
	else if(error1.equals("nodeleteError")){
		out.println("刪除成功!");
	}
	}
	String error2 = (String)request.getAttribute("error2");
	if(error2!=null){
	if(error2.equals("updateError")){
		out.println("修改失??!");
	}
	else if(error2.equals("noupdateError")){
		out.println("修改成功!");
	}
	}
	
	
	String error3 = (String)request.getAttribute("error3");
	if(error3!=null){
	if(error3.equals("uploadError")){
		out.println("上傳失??!");
	}
	else if(error3.equals("nouploadError")){
		out.println("上傳成功!");
	}
	}
	%>
		</div>
		</div>
</body>
</html>

⑧登陸成功界面css(show.css)

*{margin:0;padding:0;}
html,body
{
	font:12px/150% Arial,Verdana;
}
.content{
	background:url(../image/index.JPG);
	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;
}

⑨點(diǎn)擊學(xué)號(hào),修改學(xué)生信息界面(StudentInfo.jsp)

<%@page import="student.entity.Student"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="css/index.css" type="text/css" rel="stylesheet">
<title>修改學(xué)生信息</title>
</head>
<body>
	<%
		Student student = (Student)request.getAttribute("student");
	%>		
	<form action = "UpdateStudentServlet" method = "post">
	<div class = "content">
	<div class = "box">
	<div class = "item1">
	<h2>修改學(xué)生信息</h2>
	</div>
		<div class = "item">
		學(xué)號(hào):<input type = "text" name = "sno" value ="<%=student.getSno()%>" readonly = "readonly"/><br/>
		</div>
		<div class = "item">
		姓名:<input type = "text" name = "name" value ="<%=student.getName()%>"/><br/>
		</div>
		<div class = "item">
		年齡:<input type = "text" name = "age" value ="<%=student.getAge()%>"/><br/>
		</div>
		<div class = "item">
		專(zhuān)業(yè):<input type = "text" name = "dept" value ="<%=student.getDept()%>"/><br/>
		</div>
		<input type = "submit" class = "btn" value = "修改"/>
		<a href = "QueryStudentByPageServlet">返回</a>
		</div>
		</div>
	</form>
</body>
</html>

⑩增加學(xué)生信息(add.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="css/index.css" type="text/css" rel="stylesheet">
<script type = "text/javascript" src = "js/jquery-3.6.0.js"></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("學(xué)號(hào)有誤!必須是1-2000");
			return false;
		}
		if(!(sname.length>1&&sname.length<5)){
			alert("姓名有誤!必須是2-4位");
			return false;
		}
		if(!(sage>1&&sage<100)){
			alert("年齡有誤!必須是1-100");
			return false;
		}
		return true;
	}
	 $(document).ready(function(){
	 });
	</script>
	
<title>增加學(xué)生信息</title>
</head>
<body>
	<form action = "AddStudentServlet" method = "post"  onsubmit = "return check()">
	<div class = "content">
	<div class = "box">
	<div class = "item2">
	<h2>增加學(xué)生信息</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="學(xué)號(hào)"/><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="專(zhuān)業(yè)"/><br/>
	</div>
	<input type = "submit" class = "btn" value = "增加"/><br/>
	<a href = "QueryStudentByPageServlet">返回</a>
	</div>
	</div>
	</form>
</body>
</html>

?上傳作業(yè)操作(UpAndDown.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="css/index.css" type="text/css" rel="stylesheet">
<title>上傳作業(yè)</title>
</head>
<body>
	<form action ="UploadServlet" method = "post" enctype = "multipart/form-data">
	<div class = "content">
	<div class = "box">
	<div class = "item2">
	<h2>上傳作業(yè)</h2>
	</div>
	<div class = "item">
	<input type = "text" name="sno" placeholder="學(xué)號(hào)"/><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>

2.三層架構(gòu)

①表示層Servlet

檢查登錄的用戶名和密碼是否匹配(CheckLoginServlet.java)

package student.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;


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

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

}

注冊(cè)賬戶表示層(AddLoginIDServlet.java)

package student.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;

/**
 * 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 {
		request.setCharacterEncoding("utf-8");
		String ID = request.getParameter("UID");
		String pwd = request.getParameter("upwd");
		IStudentService studentService = new StudentServiceImpl();
		boolean result = studentService.addLoginID(ID,pwd);
		
		response.setContentType("text/html;charest=UTF-8");
		response.setCharacterEncoding("utf-8");
		if(!result) {
			request.setAttribute("error4", "addError");
			request.getRequestDispatcher("register.jsp").forward(request, response);
		}else {
			request.setAttribute("error4", "noaddError");
			request.getRequestDispatcher("login.jsp").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);
	}

}

修改密碼表示層(UpdateLoginPwdServlet.java)

package student.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;

/**
 * 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 {
		request.setCharacterEncoding("utf-8");
		String ID = request.getParameter("UID");
		String pwd = request.getParameter("upwd");
		String pwd1 = request.getParameter("upwd1");
		IStudentService service = new StudentServiceImpl();
		boolean result = service.checkLoginID(ID,pwd);
		response.setContentType("text/html;charest=UTF-8");
		response.setCharacterEncoding("utf-8");
		if(!result) {
			request.setAttribute("error0", "loginError");
			request.getRequestDispatcher("UpdateLoginPwd.jsp").forward(request, response);
		}else {
			request.setAttribute("error0", "nologinError");
			boolean result1 = service.updateLoginPwd(ID,pwd1);
			if(!result1) {
				request.getRequestDispatcher("UpdateLoginPwd.jsp").forward(request, response);
			}else {
				request.setAttribute("error1", "noupdateError");
				request.getRequestDispatcher("login.jsp").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);
	}

}

注銷(xiāo)用戶表示層(DeleteLoginIDServlet.java)

package student.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;

/**
 * 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 {
		request.setCharacterEncoding("utf-8");
		String ID = request.getParameter("UID");
		String pwd = request.getParameter("upwd");
		IStudentService service = new StudentServiceImpl();
		boolean result = service.checkLoginID(ID,pwd);
		boolean result1 = service.deleteLoginID(ID);
		response.setContentType("text/html;charest=UTF-8");
		response.setCharacterEncoding("utf-8");
		if(!result) {
			request.setAttribute("error2", "loginError");
			request.getRequestDispatcher("DeleteLoginID.jsp").forward(request, response);
		}else {
			request.setAttribute("error2", "nologinError");
			if(!result1) {
				request.setAttribute("error3", "deleteError");
				request.getRequestDispatcher("DeleteLoginID.jsp").forward(request, response);
			}else {
				request.setAttribute("error3", "nodeleteError");
				request.getRequestDispatcher("login.jsp").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);
	}

}

分頁(yè)顯示(QueryStudentByPageServlet.java)

package student.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student.entity.Page;
import student.entity.Student;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;

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 = studentService.getTotalCount();
		
		Page page = new Page();
		
		
		String cPage = request.getParameter("currentPage");
		
		if(cPage == null) {
			cPage = "0";
		}
		int currentPage = Integer.parseInt(cPage);
		page.setCurrentPage(currentPage);

		int totalCount = studentService.getTotalCount();
		page.setTotalCount(totalCount);
		int pageSize = 4;
		
		page.setPageSize(pageSize);
		
		List<Student> students = studentService.queryStudentsByPage(currentPage, pageSize);
		
		page.setStudents(students);
		request.setAttribute("page1", page);
		request.getRequestDispatcher("index.jsp").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);
	}

}

按學(xué)號(hào)查詢學(xué)生信息(QueryStudentBySnoServlet.java)

package student.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student.entity.Student;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;

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

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	request.setCharacterEncoding("UTF-8");
	int sno = Integer.parseInt(request.getParameter("sno"));
	IStudentService service = new StudentServiceImpl();
	Student student = service.queryStudentBySno(sno);
	request.setAttribute("student", student);//將查詢到的request信息放在request域中
	request.getRequestDispatcher("StudentInfo.jsp").forward(request,response);
	}

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

}

增加學(xué)生信息(AddStudentServlet.java)

package student.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student.entity.Student;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;

public class AddStudentServlet extends HttpServlet {

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

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

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

}

刪除學(xué)生信息(DeleteStudentServlet.java)

package student.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;

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

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

}

修改學(xué)生信息表示層(UpdateStudentServlet.java)

package student.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student.entity.Student;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;

public class UpdateStudentServlet extends HttpServlet {

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


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

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

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

}

上傳作業(yè)(UploadServlet.java)

package student.servlet;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadBase;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;


public class UploadServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		String name = null;
		int sno = -1;
		
		boolean isMutipart = ServletFileUpload.isMultipartContent(request);
		if(isMutipart) {
			DiskFileItemFactory factory = new DiskFileItemFactory();
			ServletFileUpload upload = new ServletFileUpload(factory);
			factory.setRepository(new File("D:\\uploadtemp"));
			List<FileItem> items = null;
				try {
					items = upload.parseRequest(request);
				} catch (FileUploadException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			Iterator<FileItem> iter = items.iterator();
			while(iter.hasNext()) {
				FileItem item= iter.next();
				String fileName = item.getName();
				String itemName = item.getFieldName();
				if(item.isFormField()) {
					if(itemName.equals("name")){
						name = item.getString("utf-8");
					}else if(itemName.equals("sno")) {
						sno =Integer.parseInt(item.getString("utf-8"));
					}else {
						
					}
				}else {
					//定義上傳路徑:指定上傳的位置
					String path = "D:\\upload";
					File file = new File(path,fileName);
						try {
							item.write(file);
							} catch (Exception e) {
							e.printStackTrace();
							}
			}
		}
		IStudentService studentService = new StudentServiceImpl();
		boolean result = studentService.upLoadWork(sno,name);
		
		System.out.println(name+sno);
		System.out.println(result);
		if(!result) {
			request.setAttribute("error3", "uploadError");
			request.getRequestDispatcher("QueryStudentByPageServlet").forward(request, response);
			
		}else{
			request.setAttribute("error3", "nouploadError");
			request.getRequestDispatcher("QueryStudentByPageServlet").forward(request, response);
			
		}
		}
	}


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

}

②業(yè)務(wù)邏輯層Service

Service接口(IStudentService.java)

package student.service;

import java.util.List;

import student.entity.Student;

public interface IStudentService {
	//查詢?nèi)繉W(xué)生信息
	public List<Student> queryAllStudents();
	//按照學(xué)號(hào)查詢學(xué)生信息
	public Student queryStudentBySno(int sno);
	//刪除學(xué)生信息
	public boolean deleteStudentBySno(int sno) ;
	
	//更改學(xué)生信息
	public boolean updateStudentBySno(int sno, Student student) ;
	
	//增加學(xué)生信息
	public boolean addStudent(Student student) ;
	
	//查詢總數(shù)據(jù)
	public int getTotalCount();
	//分頁(yè)
	public List<Student> queryStudentsByPage(int current, int pageSize);
	//檢查登陸賬戶和密碼
	public boolean checkLoginID(String ID,String pwd);
	//注冊(cè)賬戶
	public boolean addLoginID(String ID, String pwd);
	//更改密碼
	public boolean updateLoginPwd(String ID,String pwd1);
	//注銷(xiāo)賬號(hào)
	public boolean deleteLoginID(String ID);
	//判斷ID是否存在
	public boolean IDExist(String ID);
	//判斷上傳作業(yè)輸入的學(xué)生信息是否存在
	public boolean upLoadWork(int sno, String name);

}

接口的實(shí)現(xiàn)類(lèi)(StudentServiceImpl.java)

package student.service.impl;

import java.util.List;

import student.dao.IStudentDao;
import student.dao.impl.StudentDaoImpl;
import student.entity.Student;
import student.service.IStudentService;
import student.util.DBUtil;

//業(yè)務(wù)邏輯層:邏輯性的增刪改查(增:查+增),對(duì)dao層進(jìn)行的組裝
public class StudentServiceImpl implements IStudentService{
	IStudentDao studentDao = new StudentDaoImpl();
	//查詢?nèi)繉W(xué)生信息
	public List<Student> queryAllStudents(){
		return studentDao.queryAllStudents();
	}
	//按照學(xué)號(hào)查詢學(xué)生信息
	public Student queryStudentBySno(int sno) {
		return studentDao.queryStudentBySno(sno);
		
	}
	//刪除學(xué)生信息
	public boolean deleteStudentBySno(int sno) {
		if(studentDao.isExist(sno)) {
			return studentDao.deleteStudentBySno(sno);
		}
			return false;
	}
	
	
	//更改學(xué)生信息
	public boolean updateStudentBySno(int sno, Student student) {
			return studentDao.updateStudentBySno(sno, student);
	}
	
	
	//增加學(xué)生信息
	public boolean addStudent(Student student) {
		if(!studentDao.isExist(student.getSno())) {
			studentDao.addStudent(student);
			return true;
		}else {
			System.out.println("學(xué)號(hào)重復(fù)!");
			return false;
		}
	}
	
	//查詢總條數(shù)
	@Override
	public int getTotalCount() {
		return studentDao.getTotalCount();
	}
	//查詢當(dāng)前頁(yè)的數(shù)據(jù)集合
	@Override
	public List<Student> queryStudentsByPage(int current, int pageSize) {
		return studentDao.queryStudentByPage(current, pageSize);
	}
	
	
	@Override
	public boolean checkLoginID(String ID, String pwd) {
		return studentDao.checkLoginID(ID, pwd);
	}
	@Override
	public boolean addLoginID(String ID, String pwd) {
		return studentDao.addLoginID(ID,pwd);
					
	}
	@Override
	public boolean updateLoginPwd(String ID, String pwd1) {
		return studentDao.updateLoginPwd(ID,pwd1);
	}
	@Override
	public boolean deleteLoginID(String ID) {
		return studentDao.deleteLoginID(ID);
	}
	@Override
	public boolean IDExist(String ID) {
		return studentDao.IDExist(ID);
	}
	@Override
	public boolean upLoadWork(int sno, String name) {
		return studentDao.upLoadWork(sno,name);
	}
	
	
}

③數(shù)據(jù)訪問(wèn)層Dao

接口(IStudentDao.java)

package student.dao;

import java.util.List;

import student.entity.Student;

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


	//查詢?nèi)繉W(xué)生信息
	public List<Student> queryAllStudents();
	
	
	//判斷此人是否存在
	public boolean isExist(int sno) ;
	
	//增加學(xué)生信息
	public boolean addStudent(Student student);
	//刪除學(xué)生信息
	public boolean deleteStudentBySno(int sno);
	
	//根據(jù)sno找到要修改的學(xué)生,然后再進(jìn)行修改
	public boolean  updateStudentBySno(int sno,Student student);
	//根據(jù)學(xué)號(hào)查詢學(xué)生信息
	public Student queryStudentBySno(int sno);
	
	//查詢總數(shù)據(jù)數(shù)
	public int getTotalCount();
	//currentPage:當(dāng)前頁(yè)(頁(yè)碼)pageSize:頁(yè)面大?。宽?yè)顯示的數(shù)據(jù)條數(shù))
	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);
}

接口的實(shí)現(xiàn)類(lèi)(StudentDaoImpl.java)

package student.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import student.dao.IStudentDao;
import student.entity.Student;
import student.util.DBUtil;

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 = "com.mysql.cj.jdbc.Driver";
	//查詢?nèi)繉W(xué)生信息
	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 = DBUtil.executeQuery(sql, null);
			while(rs.next()) {
				int sno= rs.getInt("sno");
				String name = rs.getString("name");
				int age = rs.getInt("age");
				String dept = rs.getString("dept");
				student = new Student(name, sno, age, dept);
				students.add(student);
			}
			return students;
			
		} catch(Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			DBUtil.closeAll(rs, pstmt, DBUtil.connection);
	}
	}
	
	
	//判斷此人是否存在
	public boolean isExist(int sno) {
		return queryStudentBySno(sno) == null? false:true;
	}
	
	//增加學(xué)生信息
	public boolean addStudent(Student student) {
		String sql = "insert into student1(name,sno,age,dept) values(?,?,?,?)";
		Object[] params = {student.getName(),student.getSno(),student.getAge(),student.getDept()};
		return DBUtil.executeUpdate(sql, params);
	}
	//刪除學(xué)生信息
	public boolean deleteStudentBySno(int sno) {
		String sql = "delete from student1 where sno =?";
		Object[] params = {sno};
		return DBUtil.executeUpdate(sql, params);
	}
	
	//根據(jù)sno找到要修改的學(xué)生,然后再進(jìn)行修改
	public boolean  updateStudentBySno(int sno,Student student) {
		String sql = "update student1 set name =?,age=?,dept=? where sno=?";
		Object[] params = {student.getName(),student.getAge(),student.getDept(),sno};
		
		return DBUtil.executeUpdate(sql, params);
		
	}
	//根據(jù)學(xué)號(hào)查詢學(xué)生信息
	public Student queryStudentBySno(int sno){
		PreparedStatement pstmt = null;
		Student student = null;
		Connection connection = null;
		ResultSet rs = null;
		try {
			Class.forName(JDBC_DRIVER);
			connection = DriverManager.getConnection(URL,UserName,Pwd);
			String sql = "select * from student1 where sno = ?";
			pstmt = connection.prepareStatement(sql);
			pstmt.setInt(1, sno);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				int no= rs.getInt("sno");
				String name = rs.getString("name");
				int age = rs.getInt("age");
				String dept = rs.getString("dept");
				student = new Student(name, no, age, dept);
			}
			return student;
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch(SQLException e) {
			e.printStackTrace();
			return null;
		}catch(Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			DBUtil.closeAll(rs, pstmt, DBUtil.connection);
				}

	}


	@Override
	public int getTotalCount() {//查詢總數(shù)據(jù)數(shù)
		String sql = "select count(1) from student1";
		return DBUtil.getTotalCount(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 = DBUtil.executeQuery(sql, params);
		try {
			while(rs.next()) {
				Student student = new Student(rs.getString("name"),rs.getInt("sno"),rs.getInt("age"),rs.getString("dept"));
				students.add(student);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}
		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 = DBUtil.executeQuery(sql, params);
		try {
			while(rs.next()) {
				count++;
			}
			if(count>0)
				return true;
			else
				return false;
		} catch (SQLException e) {
			e.printStackTrace();
			}
				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 DBUtil.executeUpdate(sql, params);
	}


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


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


	@Override
	public boolean IDExist(String ID) {
		String sql = "select *from login where ID = ?";
				Object[] params = {ID};
		return DBUtil.executeUpdate(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 = DBUtil.executeQuery(sql, params);
		try {
			while(rs.next()) {
				count++;
			}
			if(count>0)
				return true;
			else
				return false;
		} catch (SQLException e) {
			e.printStackTrace();
			}
				return false;
	}
}

④通用的數(shù)據(jù)庫(kù)操作(DBUtils.java)

package student.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import student.entity.Student;

//通用的數(shù)據(jù)庫(kù)操作方法
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 = "com.mysql.cj.jdbc.Driver";
	public static Connection connection = null;
	public static PreparedStatement pstmt = null;
	public static ResultSet rs = null;
	
	//查詢總數(shù)
	public static int getTotalCount(String sql){
		int count = -1;
		try {
			pstmt = createPreParedStatement(sql,null);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				count = rs.getInt(1);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			closeAll(rs,pstmt,connection);
		}
		return count;
	}
	
	//增刪改
	public static boolean executeUpdate(String sql,Object[] params) {
		try {
			pstmt = createPreParedStatement(sql,params);
			int count = pstmt.executeUpdate();
			
			System.out.println(count);
			if(count>0) {
				return true;
			}
			else {
				return false;
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return false;
		} catch(SQLException e) {
			e.printStackTrace();
			return false;
		}catch(Exception e) {
			e.printStackTrace();
			return false;
		}
		finally {
			closeAll(null,pstmt,connection);
	}
	}
	public static void closeAll(ResultSet rs,Statement stmt,Connection connection){
		try{
			if(rs!=null)rs.close();
			if(pstmt!=null)pstmt.close();
			if(connection!=null)connection.close();
		
		}catch(SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static PreparedStatement createPreParedStatement(String sql,Object[] params) throws ClassNotFoundException, SQLException {
			pstmt = getConnection().prepareStatement(sql);
			if(params!=null) {
			for(int i = 0;i<params.length;i++) {
				pstmt.setObject(i+1, params[i]);
			}
			}
			return pstmt;
	}
	
	public static Connection getConnection() throws ClassNotFoundException, SQLException {
		Class.forName(JDBC_DRIVER);
		return DriverManager.getConnection(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 = pstmt.executeQuery();
			
			return rs;
			
		} catch(SQLException e) {
			e.printStackTrace();
			return null;
		}catch(Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}

	}

3.JavaBean封裝數(shù)據(jù)

①分頁(yè)幫助類(lèi)(Page.java)

package student.entity;

import java.util.List;

//分頁(yè)幫助類(lèi)
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) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.totalCount = totalCount;
		this.totalPage = totalPage;
		this.students = students;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
		this.totalPage = this.totalCount%this.pageSize==0?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getTotalPage() {
		return totalPage;
	}
	
	
	public List<Student> getStudents() {
		return students;
	}
	public void setStudents(List<Student> students) {
		this.students = students;
	}
}

②封裝學(xué)生信息(Student.java)

package student.entity;

public class Student {
	private String name;
	private int sno;
	private int age;
	private String dept;
	
	public Student(int sno) {
		this.sno = sno;
	}
	
	public Student() {
		
	}
	public Student(String name, int age, String dept) {
		this.name = name;
		this.age = age;
		this.dept = dept;
	}
	public Student(String name, int sno, int age, String dept) {
		this.name = name;
		this.sno = sno;
		this.age = age;
		this.dept = dept;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getSno() {
		return sno;
	}
	public void setSno(int sno) {
		this.sno = sno;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getDept() {
		return dept;
	}
	public void setDept(String dept) {
		this.dept = dept;
	}
	public String toString() {
		return this.getSno()+"-"+this.getName()+"-"+this.getAge()+"-"+this.getDept();
		
	}
}

4.項(xiàng)目所需jar包

項(xiàng)目需要3個(gè)jar包,前兩個(gè)jar包屬于文件上傳所需,最后一個(gè)為連接數(shù)據(jù)庫(kù)的jar包

下載官網(wǎng)地址:https://mvnrepository.com/
?

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

?javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

五.數(shù)據(jù)庫(kù)表格

本人用的是mysql數(shù)據(jù)庫(kù),直接在mysql數(shù)據(jù)庫(kù)中新建表格

①登錄注冊(cè)表格login

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言

②學(xué)生信息表格student1

javaweb簡(jiǎn)單的學(xué)生信息管理系統(tǒng),mvc,java,開(kāi)發(fā)語(yǔ)言文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-778301.html

到了這里,關(guān)于Javaweb學(xué)生信息管理系統(tǒng)(Mysql+JSP+MVC+CSS)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Javaee課程lab4,學(xué)生信息管理系統(tǒng)(MVC(JSP+JavaBeans+Servlet)+ JDBC)

    Javaee課程lab4,學(xué)生信息管理系統(tǒng)(MVC(JSP+JavaBeans+Servlet)+ JDBC)

    實(shí)驗(yàn)?zāi)康模?1、熟悉MVC設(shè)計(jì)模式,掌握編程思路 2、綜合運(yùn)用JSP、Servlet、JavaBean、JDBC等技術(shù)實(shí)現(xiàn)MIS系統(tǒng)—學(xué)生信息管理系統(tǒng)(鐵大) JDBC是Java Database Connectivity(Java數(shù)據(jù)庫(kù)連接)的縮寫(xiě),編程人員可以通過(guò)這個(gè)API接口連接到數(shù)據(jù)庫(kù),并使用結(jié)構(gòu)化查詢語(yǔ)言(SQL)完成對(duì)數(shù)據(jù)庫(kù)的

    2024年02月09日
    瀏覽(26)
  • 學(xué)生信息管理系統(tǒng)(mysql+jsp+servlet)

    學(xué)生信息管理系統(tǒng)(mysql+jsp+servlet)

    JDBC是Java Database Connectivity(Java數(shù)據(jù)庫(kù)連接)的縮寫(xiě),編程人員可以通過(guò)這個(gè)API接口連接到數(shù)據(jù)庫(kù),并使用結(jié)構(gòu)化查詢語(yǔ)言(SQL)完成對(duì)數(shù)據(jù)庫(kù)的查找和更新 JDBC的目標(biāo)是屏蔽不同的數(shù)據(jù)庫(kù)驅(qū)動(dòng)程序之間的差別,為開(kāi)發(fā)者提供一個(gè)標(biāo)準(zhǔn)的、純Java的數(shù)據(jù)庫(kù)程序設(shè)計(jì)接口,為在Ja

    2024年02月04日
    瀏覽(27)
  • 學(xué)生信息管理系統(tǒng)springboot學(xué)校學(xué)籍專(zhuān)業(yè)數(shù)據(jù)java jsp源代碼mysql

    學(xué)生信息管理系統(tǒng)springboot學(xué)校學(xué)籍專(zhuān)業(yè)數(shù)據(jù)java jsp源代碼mysql

    本項(xiàng)目為前幾天收費(fèi)幫學(xué)妹做的一個(gè)項(xiàng)目,Java EE JSP項(xiàng)目,在工作環(huán)境中基本使用不到,但是很多學(xué)校把這個(gè)當(dāng)作編程入門(mén)的項(xiàng)目來(lái)做,故分享出本項(xiàng)目供初學(xué)者參考。 學(xué)生信息管理系統(tǒng)springboot 系統(tǒng)3權(quán)限:超級(jí)管理員,學(xué)生,老師。 管理員登錄主要包括:用戶管理,專(zhuān)業(yè)管

    2024年02月14日
    瀏覽(19)
  • 【Jsp課設(shè)】3款基于JavaWeb的學(xué)生選課管理系統(tǒng)

    【Jsp課設(shè)】3款基于JavaWeb的學(xué)生選課管理系統(tǒng)

    ?項(xiàng)目介紹:后端采用Jsp+Servlet。前端使用的是Layui的一個(gè)網(wǎng)站模板。開(kāi)發(fā)一個(gè)在線的學(xué)生選課管理系統(tǒng),用于課程設(shè)計(jì)的使用。 項(xiàng)目類(lèi)型:JavaWeb源碼? 用戶類(lèi)型:2個(gè)角色(管理員+學(xué)生) 主要技術(shù):Jsp+Servlet+MySQL+Jquery(前端Bootstrap或者Layui) 開(kāi)發(fā)工具:Eclipse/Idea均可使用,有兩

    2024年02月04日
    瀏覽(21)
  • JAVAWEB學(xué)生信息管理系統(tǒng)保姆級(jí)教程(增刪改查+登錄注冊(cè)+Filter+mysql)eclipse版
  • java 學(xué)生信息管理系統(tǒng)Myeclipse開(kāi)發(fā)mysql數(shù)據(jù)庫(kù)web結(jié)構(gòu)jsp編程計(jì)算機(jī)網(wǎng)頁(yè)項(xiàng)目

    java 學(xué)生信息管理系統(tǒng)Myeclipse開(kāi)發(fā)mysql數(shù)據(jù)庫(kù)web結(jié)構(gòu)jsp編程計(jì)算機(jī)網(wǎng)頁(yè)項(xiàng)目

    一、源碼特點(diǎn) ?? ?java 學(xué)生信息管理系統(tǒng)是一套完善的java web信息管理系統(tǒng),對(duì)理解JSP java編程開(kāi)發(fā)語(yǔ)言有幫助,系統(tǒng)具有完整的源代碼和數(shù)據(jù)庫(kù),系統(tǒng)主要采用B/S模式開(kāi)發(fā)。開(kāi)發(fā)環(huán)境為 TOMCAT7.0,Myeclipse8.5開(kāi)發(fā),數(shù)據(jù)庫(kù)為Mysql5.0,使用java語(yǔ)言開(kāi)發(fā)。 java 學(xué)生信息管理系統(tǒng) 二、

    2024年02月09日
    瀏覽(30)
  • JavaWeb項(xiàng)目:航班信息管理系統(tǒng)(tomcat+jsp)

    JavaWeb項(xiàng)目:航班信息管理系統(tǒng)(tomcat+jsp)

    航班信息管理系統(tǒng)是學(xué)習(xí)Javaweb的一個(gè)小項(xiàng)目,首先對(duì)該項(xiàng)目的業(yè)務(wù)需求進(jìn)行分析,根據(jù)項(xiàng)目文檔知它的主要實(shí)現(xiàn)技術(shù)為 SERVLET、JSP、MVC 架構(gòu)、JDBC 和 MySQL。該項(xiàng)目著重學(xué)生的實(shí)際應(yīng)用場(chǎng)景來(lái)設(shè)計(jì),模擬 機(jī)場(chǎng)中的航班系統(tǒng)的業(yè)務(wù)實(shí)現(xiàn)以及擴(kuò)展,能夠?qū)崿F(xiàn)航班信息管理的的所有功

    2024年04月12日
    瀏覽(19)
  • JAVAWEB學(xué)生信息管理系統(tǒng)保姆級(jí)教程(增刪改查+<普通用戶和管理員>登錄注冊(cè)+Filter+mysql+批量刪除信息+用戶退出登錄注銷(xiāo))eclipse版(升級(jí)版)

    JAVAWEB學(xué)生信息管理系統(tǒng)保姆級(jí)教程(增刪改查+<普通用戶和管理員>登錄注冊(cè)+Filter+mysql+批量刪除信息+用戶退出登錄注銷(xiāo))eclipse版(升級(jí)版)

    該項(xiàng)目源碼地址: 源碼地址請(qǐng)點(diǎn)擊這里喲! ????????AdminBean.java ? ? ? ?對(duì)數(shù)據(jù)庫(kù)里的用戶名的表的數(shù)據(jù)進(jìn)行封裝。 ????????StudentBean.java ????????對(duì)數(shù)據(jù)庫(kù)里的學(xué)生信息的表的數(shù)據(jù)進(jìn)行封裝。 ????????AdminDao.java ? ? ? ? 實(shí)現(xiàn)登錄和注冊(cè)的方法。 ????????

    2024年02月08日
    瀏覽(26)
  • Java web學(xué)生信息管理系統(tǒng)(jsp)

    Java web學(xué)生信息管理系統(tǒng)(jsp)

    ??目錄 ??1 概述 1.1課程設(shè)計(jì)目的 1.2預(yù)備知識(shí) JAVAWeb: MySQL: JSP: 1.3實(shí)訓(xùn)的內(nèi)容和要求 ??2 需求分析 2.1系統(tǒng)目標(biāo) 2.2功能分析: 2.3開(kāi)發(fā)環(huán)境: ??3 設(shè)計(jì)步驟 3.1系統(tǒng)流程圖 3.3功能詳細(xì)分析 ??4 詳細(xì)設(shè)計(jì)(要有數(shù)據(jù)庫(kù)可視化表) 4.1數(shù)據(jù)庫(kù)表 ?4.2部分代碼展示: ??5 程序運(yùn)行 ??

    2024年02月03日
    瀏覽(22)
  • 基于JavaWeb的學(xué)生信息管理系統(tǒng)

    基于JavaWeb的學(xué)生信息管理系統(tǒng)

    1.系統(tǒng)分析 1.1引言 隨著我國(guó)社會(huì)主義市場(chǎng)經(jīng)濟(jì)的發(fā)展和改革開(kāi)放的不斷深入,計(jì)算機(jī)的應(yīng)用已遍及國(guó)民經(jīng)濟(jì)的各個(gè)領(lǐng)域,計(jì)算機(jī)來(lái)到我們的工作和生活中,改變著我們和周?chē)囊磺小?隨著學(xué)校的規(guī)模不斷過(guò)大,學(xué)生數(shù)量急劇増加,有關(guān)學(xué)生的各種信息量也成倍増加。面對(duì)龐

    2024年02月04日
    瀏覽(22)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包