一、背景信息:
首先,這個選課系統是上周一老師在課堂上讓我們做的測試,考試時長三個小時,我只做了一半,也沒有實現選課流程。
由於上周忙於寫實驗報告沒有時間繼續完成這個測試。這周用前天和昨天一共七個小時的時間從頭重新寫了一遍並且完
全完成所有要求,實現了選課流程和一系列增加修改操作
二、題目
石家庄鐵道大學選課管理系統
1、項目需求:
本項目所開發的學生選課系統完成學校對學生的選課信息的統計與管理,減少數據漏掉的情況,同時也節約人力、物力和財力。告別以往的人工統計。
2.系統要求與功能設計
2.1 頁面要求
(1)能夠在Tomcat服務器中正確部署,並通過瀏覽器查看;
(2)網站頁面整體風格統一;
(3)首頁(登錄頁)要求實現不同用戶登錄后,進入的功能頁不相同。
(4)教師功能頁:有添加課程、修改個人信息、瀏覽選課學生信息三個模塊。
(5)學生功能頁:有修改個人信息、瀏覽課程信息、選課三個功能模塊。
(5)管理員功能頁:有添加教師信息、添加學生信息兩個模塊。
2.2功能要求:
(1)添加教師信息:管理員可以添加教師基本信息,教師基本信息包括:教師工號(八位數字組成,例如02000081)、教師姓名、教師性別、教師所在學院、職稱(教授、副教授、講師、助教)組成;
(2)添加學生信息:管理可以添加學生基本信息,學生基本信息包括學號(八位數字組成,例如20180052)、學生姓名、學生性別、所在班級、所屬專業組成;
(3)添加課程信息:教師登陸后,可以添加自己任職的課程基本信息,課程基本信息包括:課程編號(六位數字組成,例如050013),課程名稱、選課人數、任課教師(任課教師不需錄入,那位教師填寫課程信息,那位教師就是任課教師);
(4)修改個人信息:教師或學生登陸后可以修改個人信息,但教師工號或學號不能修改,另外教師或學生只能修改自己的信息,無法看到或修改其他學生或教師的基本信息。
(5)瀏覽課程信息:學生登陸后可以看到所有課程的列表信息,點擊課程名稱可以查看課程的詳細信息,包括已選課人數。
(6)選課:進入選課頁面,課程信息列表顯示所有選課人數未達到課程設置的選課人數上限,點擊課程名稱可以看到課程詳細信息,點擊課程詳細信息頁面的“選課”按鈕,可以實現選課功能。
(7)瀏覽選課學生信息:教師進入該頁面后,可以看到自己設置的課程信息列表,點擊課程名稱,可以看到,選擇該課程的所有學生基本信息列表。
(8)登陸功能:管理員、教師、學生登陸后可以看到不同的功能頁面,教師或學生登陸后只能看到自己的相關信息,不同教師、不同學生登陸后無法查看其他人的信息。(要求至少創建兩個教師用戶、十個學生用戶演示選課過程)
3數據庫設計:
要求實現課程基本信息表、教師基本信息表、學生基本信息表、選課基本信息表。(提示:選課基本信息包括課程編號、教師編號、學號等基本信息)
4、WEB發布:
要求可以實現在瀏覽器直接訪問系統。
三、主要思路:
主要是通過jsp獲取參數或數據,然后將數據傳給servlet,servlet通過Javabean中的類和調用Dao中的方法(主要是SQL語句)處理,
然后將處理后的數據回傳給jsp進行顯示。
四、源代碼
1、Eclipse展示
login.jsp(選課系統登錄入口)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用戶登錄</title>
</head>
<body>
<table align="center" border="0px" cellpadding="10px" cellspacing="10px">
<form action="xuankeServlet?method=login" method="post" onsubmit="return check()">
<tr>
<td>用戶名:</td>
<td><input type="text" name="username" id="username"></td>
</tr>
<tr>
<td>密碼:</td>
<td><input type="password" name="password" id="password"></td>
</tr>
<tr align="center">
<th colspan="2">
<input type="submit" value="登錄">
</th>
</tr>
</form>
</table>
</body>
</html>
guanlileft.jsp(管理員左側菜單欄)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css"> .leftMenu{ background-color:#7986CB; width:250px; height:600px; position:relative; top:0px; } .menuParent{ background-color:#BBDEFB; } </style>
</head>
<body>
<div class="leftMenu">
<div class="menu">
<div class="menuParent">
<div class="ListTitlePanel">
<div class="ListTitle">
<strong>管理員菜單</strong>
<div class="leftbgbt"></div>
</div>
</div>
<div class="menuList">
<div><a target="main_right" href="addtea.jsp">添加教師信息</a></div>
<div><a target="main_right" href="addstu.jsp">添加學生信息</a></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
</script>
</body>
</html>
tealeft.jsp(教師左側菜單欄)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css"> .leftMenu{ background-color:#7986CB; width:250px; height:600px; position:relative; top:0px; } .menuParent{ background-color:#BBDEFB; } </style>
</head>
<body>
<div class="leftMenu">
<div class="menu">
<div class="menuParent">
<div class="ListTitlePanel">
<div class="ListTitle">
<strong>教師菜單</strong>
<div class="leftbgbt"></div>
</div>
</div>
<div class="menuList">
<div><a target="main_right" href="addcourse.jsp">添加課程信息</a></div>
<div><a target="main_right" href="updatet.jsp">修改個人信息</a></div>
<div><a target="main_right" href="xuankeServlet?method=liulanstu">瀏覽選課學生信息</a></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
</script>
</body>
</html>
stuleft.jsp(學生左側菜單欄)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css"> .leftMenu{ background-color:#7986CB; width:250px; height:600px; position:relative; top:0px; } .menuParent{ background-color:#BBDEFB; } </style>
</head>
<body>
<div class="leftMenu">
<div class="menu">
<div class="menuParent">
<div class="ListTitlePanel">
<div class="ListTitle">
<strong>學生菜單</strong>
<div class="leftbgbt"></div>
</div>
</div>
<div class="menuList">
<div><a target="main_right" href="xuankeServlet?method=liulankecheng">選課</a></div>
<div><a target="main_right" href="updates.jsp">修改個人信息</a></div>
<div><a target="main_right" href="xuankeServlet?method=liulankecheng1">瀏覽課程信息</a></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
</script>
</body>
</html>
addstu.jsp(添加學生信息)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加學生信息</title>
<script>
</script>
</head>
<body>
<% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %>
<script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script>
<%} %>
<table align="center" border="0px" cellpadding="10px" cellspacing="10px">
<form action="xuankeServlet?method=addstu" method="post" onsubmit="return check()">
<tr>
<td><a href="3.jsp">返回菜單</a></td>
</tr>
<tr>
<td>學號:</td>
<td><input type="text" name="spid" id="spid"></td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" name="stuname" id="stuname"></td>
</tr>
<tr>
<td>性別</td>
<td>
<select name="sex">
<option value="男">男</option>
<option value="女">女</option>
</select>
</td>
</tr>
<tr>
<td>學生所在班級:</td>
<td><input type="text" name="banji" id="banji"></td>
</tr>
<tr>
<td>所屬專業:</td>
<td><input type="text" name="ye" id="ye"></td>
</tr>
<tr align="center">
<th colspan="2">
<input type="submit" value="提交">
</th>
</tr>
</form>
</table>
</body>
</html>
addtea.jsp(添加教師信息)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加教師信息</title>
<script>
</script>
</head>
<body>
<% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %>
<script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script>
<%} %>
<table align="center" border="0px" cellpadding="10px" cellspacing="10px">
<form action="xuankeServlet?method=addtea" method="post" onsubmit="return check()">
<tr>
<td><a href="3.jsp">返回菜單</a></td>
</tr>
<tr>
<td>教師工號:</td>
<td><input type="text" name="tpid" id="tpid"></td>
</tr>
<tr>
<td>教師姓名:</td>
<td><input type="text" name="teaname" id="teaname"></td>
</tr>
<tr>
<td>性別</td>
<td>
<select name="sex">
<option value="男">男</option>
<option value="女">女</option>
</select>
</td>
</tr>
<tr>
<td>教師所在學院:</td>
<td><input type="text" name="txueyuan" id="txueyuan"></td>
</tr>
<tr>
<td>職稱:</td>
<td>
<select name="zhicheng">
<option value="教授">教授</option>
<option value="副教授">副教授</option>
<option value="講師">講師</option>
<option value="助教">助教</option>
</select>
</td>
</tr>
<tr align="center">
<th colspan="2">
<input type="submit" value="提交">
</th>
</tr>
</form>
</table>
</body>
</html>
addcourse.jsp(添加課程信息)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加學生信息</title>
<script>
</script>
</head>
<body>
<% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %>
<script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script>
<%} %>
<table align="center" border="0px" cellpadding="10px" cellspacing="10px">
<form action="xuankeServlet?method=addcou" method="post" onsubmit="return check()">
<tr>
<td><a href="1.jsp">返回菜單</a></td>
</tr>
<tr>
<td>課程編號:</td>
<td><input type="text" name="cpid" id="cpid"></td>
</tr>
<tr>
<td>課程名稱:</td>
<td><input type="text" name="cname" id="cname"></td>
</tr>
<tr>
<td>選課人數:</td>
<td><input type="text" name="num" id="num"></td>
</tr>
<tr>
<tr align="center">
<th colspan="2">
<input type="submit" value="提交">
</th>
</tr>
</form>
</table>
</body>
</html>
houtai.jsp(這個jsp主要是不同用戶登錄,跳轉到不同主界面)(主界面就是左側菜單欄,上部是一個菜單欄,右側是一個空白的顯示框)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>菜單</title>
</head>
<body>
<a href="${pid}.jsp">菜單</a>
</body>
</html>
1.jsp (學生主界面)
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>選課系統</title>
</head>
<frameset rows="20%,*">
<frame class="top" src="top.jsp">
<frameset cols="20%,*">
<frame src="tealeft.jsp">
<frame src="main_right.jsp" name="main_right">
</frameset>
</frameset>
<body>
</body>
</html>
2.jsp(教師主界面)
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>選課系統</title>
</head>
<frameset rows="20%,*">
<frame class="top" src="top.jsp">
<frameset cols="20%,*">
<frame src="stuleft.jsp">
<frame src="main_right.jsp" name="main_right">
</frameset>
</frameset>
<body>
</body>
</html>
3.jsp (管理員主界面)
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>選課系統</title>
</head>
<frameset rows="20%,*">
<frame class="top" src="top.jsp">
<frameset cols="20%,*">
<frame src="guanlileft.jsp">
<frame src="main_right.jsp" name="main_right">
</frameset>
</frameset>
<body>
</body>
</html>
top.jsp(頭部菜單欄)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css"> .headdiv{ background-color:#3F51B5; width:100%; height:130px; } .headdiv P{ font-family:YouYuan; font-size:20px; color:#E8EAF6; position:relative; left:20px; top:45px; } </style>
</head>
<body>
<div class="headdiv">
<p>選課系統</p>
</div>
</body>
</html>
main_right.jsp(右側空白顯示框)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
chakankecheng.jsp(顯示課程詳細信息)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>課程信息詳情</title>
<style> .a{ margin-top: 20px; } .b{ font-size: 20px; width: 160px; color: white; background-color: greenyellow; } .tb, td { border: 0px solid black; font-size: 22px; } </style>
</head>
<body>
<div align="center">
<h1 style="color: black;">課程詳細信息</h1>
<table class="tb">
<tr>
<td><a href="2.jsp">返回菜單</a></td>
</tr>
<tr>
<td>課程編號</td>
<td>課程名稱</td>
<td>課程容量</td>
<td>課程選課人數</td>
<td>任課教師</td>
</tr>
<tr>
<td>${cou.cpid}</td>
<td>${cou.cname}</td>
<td>${cou.num}</td>
<td>${cou.snum}</td>
<td>${cou.jiaoshi}</td>
</tr>
</table>
<table align="center" border="0px" cellpadding="10px" cellspacing="10px">
<form action="xuankeServlet?method=xuanke" method="post" onsubmit="return check()">
<tr>
<td><input type="hidden" name="cpid" id="cpid" value="${cou.cpid}"></td>
</tr>
<tr>
<td><input type="hidden" name="snum" id="snum" value="${cou.snum}"></td>
</tr>
<tr>
<td><input type="hidden" name="jiaoshi" id="jiaoshi" value="${cou.jiaoshi}"></td>
</tr>
<tr align="center">
<th colspan="2">
<input type="submit" value="選課">
</th>
</tr>
</form>
</table>
</div>
</body>
</html>
liulankecheng.jsp(只顯示課程名,且課程名帶超鏈接的列表信息)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %>
<script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script>
<%} %>
<div align="center">
<h1 style="color: black;">課程信息列表</h1>
<table class="tb">
<tr>
<td> 課程名稱 </td>
</tr>
<c:forEach items="${cous}" var="item">
<tr>
<td> <a href="xuankeServlet?method=chakan&id=${item.id}">${item.cname}</a></td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
liulankecheng1.jsp(顯示所有課程的信息信息)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %>
<script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script>
<%} %>
<div align="center">
<h1 style="color: black;">課程信息列表</h1>
<table class="tb">
<tr>
<td><a href="2.jsp">返回菜單</a></td>
</tr>
<tr>
<td>課程編號</td>
<td>課程名稱</td>
<td>課程容量</td>
<td>課程選課人數</td>
<td>任課教師</td>
</tr>
<c:forEach items="${cous}" var="item">
<tr>
<td>${item.cpid}</td>
<td>${item.cname}</td>
<td>${item.num}</td>
<td>${item.snum}</td>
<td>${item.jiaoshi}</td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
liulanstu.jsp(瀏覽選課學生信息)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %>
<script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script>
<%} %>
<div align="center">
<h1 style="color: black;">課程信息列表</h1>
<table class="tb">
<tr>
<td><a href="2.jsp">返回菜單</a></td>
</tr>
<tr>
<td>學生學號</td>
<td>學生姓名</td>
<td>學生性別</td>
<td>學生所在班級</td>
<td>學生專業</td>
</tr>
<c:forEach items="${jibens}" var="item">
<tr>
<td>${item.spid}</td>
<td>${item.stuname}</td>
<td>${item.sex}</td>
<td>${item.banji}</td>
<td>${item.ye}</td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
sucess.jsp(選課成功后的界面)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %>
<script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script>
<%} %>
<table align="center" border="0px" cellpadding="10px" cellspacing="10px">
<tr>
<td><a href="xuankeServlet?method=liulankecheng">返回選課</a></td>
</tr>
</table>
</body>
</html>
updatet.jsp(修改教師信息)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改教師信息</title>
<script>
</script>
</head>
<body>
<% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %>
<script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script>
<%} %>
<table align="center" border="0px" cellpadding="10px" cellspacing="10px">
<form action="xuankeServlet?method=updatetea" method="post" onsubmit="return check()">
<tr>
<td><a href="1.jsp">返回菜單</a></td>
</tr>
<tr>
<td>教師姓名:</td>
<td><input type="text" name="teaname" id="teaname"></td>
</tr>
<tr>
<td>性別</td>
<td>
<select name="sex">
<option value="男">男</option>
<option value="女">女</option>
</select>
</td>
</tr>
<tr>
<td>教師所在學院:</td>
<td><input type="text" name="txueyuan" id="txueyuan"></td>
</tr>
<tr>
<td>職稱:</td>
<td>
<select name="zhicheng">
<option value="教授">教授</option>
<option value="副教授">副教授</option>
<option value="講師">講師</option>
<option value="助教">助教</option>
</select>
</td>
</tr>
<tr align="center">
<th colspan="2">
<input type="submit" value="提交">
</th>
</tr>
</form>
</table>
</body>
</html>
updates.jsp(修改學生信息)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改學生信息</title>
<script>
</script>
</head>
<body>
<% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %>
<script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script>
<%} %>
<table align="center" border="0px" cellpadding="10px" cellspacing="10px">
<form action="xuankeServlet?method=updatestu" method="post" onsubmit="return check()">
<tr>
<td><a href="2.jsp">返回菜單</a></td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" name="stuname" id="stuname"></td>
</tr>
<tr>
<td>性別</td>
<td>
<select name="sex">
<option value="男">男</option>
<option value="女">女</option>
</select>
</td>
</tr>
<tr>
<td>學生所在班級:</td>
<td><input type="text" name="banji" id="banji"></td>
</tr>
<tr>
<td>所屬專業:</td>
<td><input type="text" name="ye" id="ye"></td>
</tr>
<tr align="center">
<th colspan="2">
<input type="submit" value="提交">
</th>
</tr>
</form>
</table>
</body>
</html>
Servlet:
xuankeServlet.java
package xuankeServlet; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Dao.Dao; import Javabean.Cou; import Javabean.Jibenxinxi; import Javabean.Stu; import Javabean.Teacher; @WebServlet("/xuankeServlet") public class xuankeServlet extends HttpServlet{ /** * 特有id號 */
private static final long serialVersionUID = 1L; Dao dao = new Dao(); /** * 方法選擇 * @return * @throws IOException * @throws ServletException */
protected void service(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String method = req.getParameter("method"); if("login".equals(method)) { login(req,resp); }else if("addtea".equals(method)) { addtea(req,resp); }else if("addstu".equals(method)) { addstu(req,resp); }else if("addcou".equals(method)) { addcou(req,resp); }else if("updatetea".equals(method)) { updatetea(req,resp); }else if("updatestu".equals(method)) { updatestu(req,resp); }else if("liulankecheng".equals(method)) { liulankecheng(req,resp); }else if("chakan".equals(method)) { chakan(req,resp); }else if("xuanke".equals(method)) { xuanke(req,resp); }else if("liulankecheng1".equals(method)) { liulankecheng1(req,resp); }else if("liulanstu".equals(method)) { liulanstu(req,resp); } } private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub
req.setCharacterEncoding("utf-8"); String username = req.getParameter("username"); String password=req.getParameter("password"); int pid=dao.searchPid(username,password); System.out.println(pid); if(pid==1) { String teaname=dao.searchteaname(username); System.out.println(teaname); req.getSession().setAttribute("username", username); req.getSession().setAttribute("teaname", teaname); } if(pid==2) { req.getSession().setAttribute("username1", username); } req.setAttribute("pid", pid); req.getRequestDispatcher("houtai.jsp").forward(req, resp); } private void addtea(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String tpid = req.getParameter("tpid"); String teaname = req.getParameter("teaname"); String sex = req.getParameter("sex"); String txueyuan = req.getParameter("txueyuan"); String zhicheng = req.getParameter("zhicheng"); int pid=1; String password = "123456"; Teacher teacher=new Teacher(tpid,teaname,sex,txueyuan,zhicheng); if(dao.addtea(teacher)&&dao.adduser(tpid,password,pid)) { req.setAttribute("teacher",teacher); req.setAttribute("message","添加成功" ); req.getRequestDispatcher("addtea.jsp").forward(req, resp); }else { req.setAttribute("message","老師姓名重復,請重新輸入" ); req.getRequestDispatcher("addtea.jsp").forward(req, resp); } } private void addstu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String spid = req.getParameter("spid"); String stuname = req.getParameter("stuname"); String sex = req.getParameter("sex"); String banji = req.getParameter("banji"); String ye = req.getParameter("ye"); Stu stu=new Stu(spid,stuname,sex,banji,ye); int pid=2; String password="123456"; if(dao.addstu(stu)&&dao.adduser(spid, password, pid)) { req.setAttribute("stu",stu); req.setAttribute("message","添加成功" ); req.getRequestDispatcher("addstu.jsp").forward(req, resp); }else { req.setAttribute("message","學生姓名重復,請重新輸入" ); req.getRequestDispatcher("addstu.jsp").forward(req, resp); } } private void addcou(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String jiaoshi=(String) req.getSession().getAttribute("teaname"); String cpid = req.getParameter("cpid"); String cname = req.getParameter("cname"); int num = Integer.parseInt(req.getParameter("num")); int snum=0; System.out.println(jiaoshi); Cou cou=new Cou(cpid,cname,num,snum,jiaoshi); if(dao.addcou(cou)) { req.setAttribute("cou",cou); req.setAttribute("message","添加成功" ); req.getRequestDispatcher("addcourse.jsp").forward(req, resp); }else { req.setAttribute("message","課程信息重復,請重新輸入" ); req.getRequestDispatcher("addcourse.jsp").forward(req, resp); } } private void updatetea(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String tpid=(String) req.getSession().getAttribute("username"); String teaname = req.getParameter("teaname"); String sex = req.getParameter("sex"); String txueyuan = req.getParameter("txueyuan"); String zhicheng = req.getParameter("zhicheng"); Teacher teacher=new Teacher(tpid,teaname,sex,txueyuan,zhicheng); if(dao.updatetea(teacher)) { req.setAttribute("message","修改成功" ); req.getRequestDispatcher("updatet.jsp").forward(req, resp); } else { req.setAttribute("message","修改失敗" ); req.getRequestDispatcher("updatet.jsp").forward(req, resp); } } private void updatestu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String spid =(String) req.getSession().getAttribute("username1"); String stuname = req.getParameter("stuname"); String sex = req.getParameter("sex"); String banji = req.getParameter("banji"); String ye = req.getParameter("ye"); Stu stu=new Stu(spid,stuname,sex,banji,ye); if(dao.updatestu(stu)) { req.setAttribute("message","修改成功" ); req.getRequestDispatcher("updates.jsp").forward(req, resp); } else { req.setAttribute("message","修改失敗" ); req.getRequestDispatcher("updates.jsp").forward(req, resp); } } private void liulankecheng(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); List<Cou> cous = dao.liulankecheng(); req.setAttribute("cous", cous); req.getRequestDispatcher("liulankecheng.jsp").forward(req, resp); } private void chakan(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); int id = Integer.parseInt(req.getParameter("id")); Cou cou=dao.searchByid(id); req.getSession().setAttribute("id", id); req.setAttribute("cou", cou); req.getRequestDispatcher("chakankecheng.jsp").forward(req, resp); } private void xuanke(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String spid =(String) req.getSession().getAttribute("username1"); String cpid = req.getParameter("cpid"); int snum = Integer.parseInt(req.getParameter("snum"))+1; String jiaoshi = req.getParameter("jiaoshi"); int id =(int) req.getSession().getAttribute("id"); String tpid=dao.searchtpid(jiaoshi); Stu stu = dao.searchstu(spid); System.out.println(id); if(dao.updatecou(id,snum)&&dao.addjiben(cpid,tpid,spid,stu)) { req.setAttribute("message","選課成功" ); req.getRequestDispatcher("sucess.jsp").forward(req, resp); } else { req.setAttribute("message","選課失敗" ); req.getRequestDispatcher("sucess.jsp").forward(req, resp); } } private void liulankecheng1(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); List<Cou> cous = dao.liulankecheng1(); req.setAttribute("cous", cous); req.getRequestDispatcher("liulankecheng1.jsp").forward(req, resp); } private void liulanstu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String tpid=(String) req.getSession().getAttribute("username"); List<Jibenxinxi> jibens = dao.searchstuinfo(tpid); req.setAttribute("jibens",jibens); req.getRequestDispatcher("liulanstu.jsp").forward(req, resp); } }
Javabean:
Cou.java (課程信息類)
package Javabean; public class Cou { private int id; private String cpid; private String cname; private int num; private int snum; private String jiaoshi; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getCpid() { return cpid; } public void setCpid(String cpid) { this.cpid = cpid; } public String getCname() { return cname; } public void setCname(String cname) { this.cname = cname; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } public int getSnum() { return snum; } public void setSnum(int snum) { this.snum = snum; } public String getJiaoshi() { return jiaoshi; } public void setJiaoshi(String jiaoshi) { this.jiaoshi = jiaoshi; } public Cou() {} public Cou(int id,String cpid,String cname,int num,int snum,String jiaoshi) { this.id=id; this.cpid=cpid; this.cname=cname; this.num=num; this.snum=snum; this.jiaoshi=jiaoshi; } public Cou(String cpid,String cname,int num,int snum,String jiaoshi) { this.cpid=cpid; this.cname=cname; this.num=num; this.snum=snum; this.jiaoshi=jiaoshi; } }
Teacher.java (教師信息類)
package Javabean; public class Teacher { private int id; private String tpid; private String teaname; private String sex; private String txueyuan; private String zhicheng; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTpid() { return tpid; } public void setTpid(String tpid) { this.tpid = tpid; } public String getTeaname() { return teaname; } public void setTeaname(String teaname) { this.teaname = teaname; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getTxueyuan() { return txueyuan; } public void setTxueyuan(String txueyuan) { this.txueyuan = txueyuan; } public String getZhicheng() { return zhicheng; } public void setZhicheng(String zhicheng) { this.zhicheng = zhicheng; } public Teacher() { } public Teacher(int id,String tpid,String teaname,String sex,String txueyuan,String zhicheng) { this.id=id; this.tpid=tpid; this.teaname=teaname; this.sex=sex; this.txueyuan=txueyuan; this.zhicheng=zhicheng; } public Teacher(String tpid,String teaname,String sex,String txueyuan,String zhicheng) { this.tpid=tpid; this.teaname=teaname; this.sex=sex; this.txueyuan=txueyuan; this.zhicheng=zhicheng; } }
Stu.java (學生信息類)
package Javabean; public class Stu { private int id; private String spid; private String stuname; private String sex; private String banji; private String ye; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getSpid() { return spid; } public void setSpid(String spid) { this.spid = spid; } public String getStuname() { return stuname; } public void setStuname(String stuname) { this.stuname = stuname; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getBanji() { return banji; } public void setBanji(String banji) { this.banji = banji; } public String getYe() { return ye; } public void setYe(String ye) { this.ye = ye; } public Stu() { } public Stu(int id,String spid,String stuname,String sex,String banji,String ye) { this.id=id; this.spid=spid; this.stuname=stuname; this.sex=sex; this.banji=banji; this.ye=ye; } public Stu(String spid,String stuname,String sex,String banji,String ye) { this.spid=spid; this.stuname=stuname; this.sex=sex; this.banji=banji; this.ye=ye; } }
Jibenxinxi.java(選課學生信息類)
package Javabean; public class Jibenxinxi { private int id; private String cpid; private String tpid; private String spid; private String stuname; private String sex; private String banji; private String ye; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getCpid() { return cpid; } public void setCpid(String cpid) { this.cpid = cpid; } public String getTpid() { return tpid; } public void setTpid(String tpid) { this.tpid = tpid; } public String getSpid() { return spid; } public void setSpid(String spid) { this.spid = spid; } public String getStuname() { return stuname; } public void setStuname(String stuname) { this.stuname = stuname; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getBanji() { return banji; } public void setBanji(String banji) { this.banji = banji; } public String getYe() { return ye; } public void setYe(String ye) { this.ye = ye; } public Jibenxinxi() { } public Jibenxinxi(int id,String cpid,String tpid,String spid,String stuname,String sex,String banji,String ye) { this.id=id; this.cpid=cpid; this.tpid=tpid; this.spid=spid; this.stuname=stuname; this.sex=sex; this.banji=banji; this.ye=ye; } public Jibenxinxi(String cpid,String tpid,String spid,String stuname,String sex,String banji,String ye) { this.cpid=cpid; this.tpid=tpid; this.spid=spid; this.stuname=stuname; this.sex=sex; this.banji=banji; this.ye=ye; } }
Dao:
Dao.java(進行與數據庫的交互,主要是SQL語句)
package Dao; import java.sql.Connection; 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 DBUtil.DBUtil; import Javabean.Cou; import Javabean.Jibenxinxi; import Javabean.Stu; import Javabean.Teacher; public class Dao { public int searchPid(String username,String password) { Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; int pid=0; try { String sql="select pid from user where username= '"+username+"' and password='"+password+"'"; state = conn.createStatement(); rs = state.executeQuery(sql); while(rs.next()){ pid = rs.getInt("pid"); } } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } return pid; } public boolean addtea(Teacher teacher) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into teacher(tpid,teaname,sex,txueyuan,zhicheng) value(?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, teacher.getTpid()); pstmt.setString(2, teacher.getTeaname()); pstmt.setString(3, teacher.getSex()); pstmt.setString(4, teacher.getTxueyuan()); pstmt.setString(5, teacher.getZhicheng()); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public boolean adduser(String tpid,String password,int pid) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into user(username,password,pid) value(?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, tpid); pstmt.setString(2, password); pstmt.setInt(3, pid); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public boolean addstu(Stu stu) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into stu(spid,stuname,sex,banji,ye) value(?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, stu.getSpid()); pstmt.setString(2, stu.getStuname()); pstmt.setString(3, stu.getSex()); pstmt.setString(4, stu.getBanji()); pstmt.setString(5, stu.getYe()); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public String searchteaname(String tpid) { Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; String teaname=null; try { String sql="select teaname from teacher where tpid= '"+tpid+"'"; state = conn.createStatement(); rs = state.executeQuery(sql); while(rs.next()){ teaname = rs.getString("teaname"); } } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } return teaname; } public boolean addcou(Cou cou) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into cou(cpid,cname,num,snum,jiaoshi) value(?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, cou.getCpid()); pstmt.setString(2, cou.getCname()); pstmt.setInt(3, cou.getNum()); pstmt.setInt(4, cou.getSnum()); pstmt.setString(5, cou.getJiaoshi()); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public boolean updatetea(Teacher teacher) { String sql = "update teacher set teaname='" + teacher.getTeaname() + "', sex='" + teacher.getSex() + "', txueyuan='" +teacher.getTxueyuan() + "',zhicheng='" +teacher.getZhicheng() + "'where tpid='" + teacher.getTpid() + "'"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); System.out.println("看看是不是執行了"); a = state.executeUpdate(sql); System.out.println(a); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } System.out.println(f); return f; } public boolean updatestu(Stu stu) { String sql = "update stu set stuname='" + stu.getStuname() + "', sex='" + stu.getSex() + "', banji='" +stu.getBanji() + "',ye='" +stu.getYe() + "'where spid='" + stu.getSpid() + "'"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); System.out.println("看看是不是執行了"); a = state.executeUpdate(sql); System.out.println(a); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } System.out.println(f); return f; } public List<Cou> liulankecheng() { String sql = "select * from cou"; List<Cou> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Cou bean = null; while (rs.next()) { int id = rs.getInt("id"); String cpid = rs.getString("cpid"); String cname = rs.getString("cname"); int num = rs.getInt("num"); int snum = rs.getInt("snum"); String jiaoshi = rs.getString("jiaoshi"); bean = new Cou(id,cpid, cname, num ,snum,jiaoshi); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } public Cou searchByid(int id) { String sql = "select * from cou where id= '"+id+"'"; Cou cou = null; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { //int id = rs.getInt("id");
String cpid = rs.getString("cpid"); String cname = rs.getString("cname"); int num = rs.getInt("num"); int snum = rs.getInt("snum"); String jiaoshi = rs.getString("jiaoshi"); cou = new Cou(cpid, cname, num ,snum,jiaoshi); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return cou; } public boolean updatecou(int id,int snum) { String sql="update cou set snum='" + snum + "'where id='" + id +"'"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); System.out.println("看看是不是執行了"); a = state.executeUpdate(sql); System.out.println(a); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } System.out.println(f); return f; } public String searchtpid(String jiaoshi) { String sql = "select tpid from teacher where teaname= '"+jiaoshi+"'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; String tpid=null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { tpid=rs.getString("tpid"); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return tpid; } public Stu searchstu(String spid) { String sql = "select * from stu where spid= '"+spid+"'"; Stu stu = null; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { //int id = rs.getInt("id");
String spid1 = rs.getString("spid"); String stuname = rs.getString("stuname"); String sex = rs.getString("sex"); String banji = rs.getString("banji"); String ye = rs.getString("ye"); stu = new Stu(spid1, stuname, sex ,banji,ye); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return stu; } public boolean addjiben(String cpid,String tpid,String spid,Stu stu) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into jiben(cpid,tpid,spid,stuname,sex,banji,ye) value(?,?,?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, cpid); pstmt.setString(2, tpid); pstmt.setString(3, spid); pstmt.setString(4, stu.getStuname()); pstmt.setString(5, stu.getSex()); pstmt.setString(6, stu.getBanji()); pstmt.setString(7, stu.getYe()); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public List<Cou> liulankecheng1() { String sql = "select * from cou"; List<Cou> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Cou bean = null; while (rs.next()) { int id = rs.getInt("id"); String cpid = rs.getString("cpid"); String cname = rs.getString("cname"); int num = rs.getInt("num"); int snum = rs.getInt("snum"); String jiaoshi = rs.getString("jiaoshi"); if(snum<num) { bean = new Cou(id,cpid, cname, num ,snum,jiaoshi); list.add(bean); } } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } public List<Jibenxinxi> searchstuinfo(String tpid) { String sql = "select * from jiben where tpid= '"+tpid+"'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; List<Jibenxinxi> list = new ArrayList<>(); try { state = conn.createStatement(); rs = state.executeQuery(sql); Jibenxinxi jiben = null; while (rs.next()) { //int id = rs.getInt("id");
String cpid = rs.getString("cpid"); String tpid1 = rs.getString("tpid"); String spid = rs.getString("spid"); String stuname = rs.getString("stuname"); String sex = rs.getString("sex"); String banji = rs.getString("banji"); String ye = rs.getString("ye"); jiben = new Jibenxinxi(cpid,tpid1,spid,stuname,sex ,banji,ye); list.add(jiben); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } }
DBUtil:
DBUtil.java (獲取數據庫連接和釋放與數據庫的連接)
package DBUtil; import java.sql.*; /** * 數據庫連接工具 * @author Hu * */
public class DBUtil { public static String url = "jdbc:mysql://localhost:3306/xuanke?serverTimezone=UTC"; public static String user = "root"; public static String password = "123"; public static Connection getConn () { Connection conn = null; try { Class.forName("com.mysql.cj.jdbc.Driver");//加載驅動
conn = DriverManager.getConnection(url, user, password); } catch (Exception e) { e.printStackTrace(); } return conn; } /** * 關閉連接 * @param state * @param conn */
public static void close (PreparedStatement preparedState, Connection conn) { if (preparedState != null) { try { preparedState.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, PreparedStatement preparedState, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (preparedState != null) { try { preparedState.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } /** * 關閉連接 * @param state * @param conn */
public static void close (Statement state, Connection conn) { if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, Statement state, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void main(String[] args) throws SQLException { Connection conn = getConn(); PreparedStatement preparedStatement = null; ResultSet rs = null; String sql ="select * from xuanke"; preparedStatement = conn.prepareStatement(sql); rs = preparedStatement.executeQuery(); if(rs.next()){ System.out.println("數據庫為空"); } else{ System.out.println("數據庫不為空"); } } }
架包:
四、數據庫設計
數據庫展示:
cou表設計(課程信息表)
jiben表設計(選課學生信息表)
stu表設計(學生信息表)
teacher表設計(教師信息表)
user表設計(用戶信息表,用戶包括管理員、教師和學生)
五、運行效果展示
首先在user表中加入管理員信息
然后運行login.jsp,用username和password做用戶名和密碼
點擊登錄,出現如下界面,再點擊菜單
進入管理員主頁
點擊添加教師信息,輸入教師信息,點擊提交
看數據庫teacher表,教師信息已存入表中
點擊添加學生信息,輸入學生信息,點擊提交
看數據庫stu表,學生信息已存入表中
剛才添加的教師信息中教師編號即為教師登錄的用戶名,密碼都默認為123456,剛才添加的學生信息中學生學號即為學生登錄的用戶名,密碼也默認為123456,並且數據已經存入user表中了
接下來,用剛添加的教師編號去登錄名叫張三的教師賬號
點擊登錄,出現如下界面,再點擊菜單
進入教師主界面
點擊添加課程,輸入課程信息,點擊提交
看數據庫cou表,課程信息已存入表中,由於是張三老師登錄,所以任課教師為張三,而snum是已選課人數,即當前選擇這門課人數為0
點擊修改個人信息,並填寫教師信息,點擊提交
查看teacher表,可以看到張三教師信息已修改
由於當前沒有學生選課,所以瀏覽學生選課信息為空,我們用剛添加的王五同學賬號登錄去選課,用戶名為王五同學學號,密碼默認為123456,輸入信息,點擊登錄
點擊菜單,進入學生主界面
點擊瀏覽課程信息,可以看見剛才張三教師添加的課程信息
然后點擊選課
點擊離散數學,可查看課程詳細信息,點擊選課
點擊返回選課,回到選課最初界面
此時再點擊瀏覽課程瀏覽信息,可以看見張三教師的離散數學選課人數由0變為1了
這時候,再退出登錄,重新登錄張三教師賬號,點擊瀏覽選課學生信息,可以看見剛才選擇張三教師的離散數學的王五同學的信息
而登錄其他教師賬號(比如說教師編號20173506的風一教師賬號,點擊瀏覽選課學生信息,則不會看到王五同學的信息)
繼續登錄王五同學賬號,點擊修改個人信息,點擊提交
查看stu表,可以看到王五學生信息已修改
這個選課系統的運行效果展示結束
以上就是這個選課系統的所有內容,希望與博客園的朋友們共同學習,如果有不足之處,歡迎各位大佬們指正。