基于javaweb+mysql的学生在线选课系统(管理员、教师、学生)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
内容:源码+数据库脚本+word报告文档
管理员:个人信息、学生、老师、学生、课程等管理
教师:个人信息、成绩、选课管理、教室查看
学生:个人信息、成绩查看、选课和查看
eclipse或MyEclipse或idea
管理员
学生
教师
技术框架
CSS JavaScript JSP Servlet JDBC MySQL
String cid=rs.getString("cId");
String cname=rs.getString("cName");
String credit=rs.getString("credit");
String period=rs.getString("period");
String cplace=rs.getString("cPlace");
String cnum=rs.getString("cNum");
course=new LookCourse(cid,cname,credit,period,cplace,cnum);
courses.add(course);
}
return courses;
}catch(ClassNotFoundException e) {
e.printStackTrace();
return null;
}catch(SQLException e) {
e.printStackTrace();
return null;
}catch(Exception e) {
e.printStackTrace();
return null;
}finally {
try {
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
</head>
<body>
<div id="wrapper">
<main id="middle">
<div>
<div id="mainLeft">
<div id="nav-wrapper">
<nav>
<div>
<h2 id="hea">学生选课系统</h2><br>
<ul>
<li>
<a href="StuQueryBySidServlet?sid=<%=(String)session.getAttribute("id")%>">个人信息</a><hr>
</li>
<li>
<a href="stuMessMod.jsp">密码修改</a><hr>
</li>
<li>
<a href="StuGradeQueryServlet?sid=<%=(String)session.getAttribute("id")%>">成绩查询</a><hr>
</li>
<li>
<a href="StuCourseQueryServlet?sid=<%=(String)session.getAttribute("id")%>">选课查询以及退选</a><hr>
border-bottom-left-radius: 0px;
box-shadow: 0 0 5px #aaa;
}
#mainLeft h2 {
margin-bottom: 0.2em;
font-size: 1.2em;
}
#mainLeft ul {
padding: 0;
margin: 0;
list-style-type: none;
background-color:white;
}
public String getcPlace() {
return cPlace;
}
public void setcPlace(String cPlace) {
this.cPlace = cPlace;
}
public String getcNumAll() {
return cNumAll;
}
public void setcNumAll(String cNumAll) {
this.cNumAll = cNumAll;
}
public String getcNum() {
return cNum;
}
public void setcNum(String cNum) {
this.cNum = cNum;
}
public String gettName() {
return tName;
}
public void settName(String tName) {
this.tName = tName;
}
public String getdId() {
e.printStackTrace();
return false;
}catch(Exception e) {
e.printStackTrace();
return false;
}finally {
try {
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
}
//根据教师号删除教师
public boolean deleteTeaByTid(String tid) {
Connection connection=null;
PreparedStatement pstmt=null;
int row;
e.printStackTrace();
return false;
}finally {
try {
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
}
public List<Teacher> allteacherQuery() {
Connection connection=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
if(!result) { //注册失败
request.setAttribute("error", "addError");
}
else { //注册成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("addstudent.jsp").forward(request, response); //StudentQueryAllServlet直接转发给StudentInfoList.jsp,不需要进行处理
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
package com.demo.vo;
public class Teacher {
private String tId;
private String tName;
private String tPass;
private String dId;
private String tSex;
private String tAge;
private String tEdu;
//根据学号修改学生信息
public boolean updateBySid(String sid,String pass) {
if(studentDao.isExist(sid)) { //学生存在
return studentDao.updateBySid(sid,pass);
}
else {
return false;
}
}
//学生课程退选 及 该课程“已选人数”减1
public boolean courseDelete(String sid,String cid) {
if(studentDao.isExistRecord(sid,cid)) { //选修记录存在
return studentDao.courseDelete(sid,cid) & studentDao.cutCourseNum(cid);
}
else {
out.println("注册成功!");
response.sendRedirect("StudentQueryAllServlet");
}
else {
out.println("注册失败,该学生已存在,请检查学号是否正确!");
}*/
if(!result) { //注册失败
request.setAttribute("error", "addError");
}
else { //注册成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("addteacher.jsp").forward(request, response); //StudentQueryAllServlet直接转发给StudentInfoList.jsp,不需要进行处理
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
private String tPass;
private String dId;
private String tSex;
private String tAge;
private String tEdu;
private String tTitle;
private String tSch;
private String tHealth;
public Teacher(String tId, String tName, String tPass, String dId, String tSex, String tAge, String tEdu,String tTitle,String tSch,String tHealth) {
this.tId = tId;
this.tName = tName;
this.tPass = tPass;
this.dId = dId;
this.tSex = tSex;
this.tAge = tAge;
this.tEdu = tEdu;
this.tTitle=tTitle;
this.tSch=tSch;
this.tHealth=tHealth;
}
public String gettId() {
students.add(student);
}
return students;
}catch(ClassNotFoundException e) {
e.printStackTrace();
return null;
}catch(SQLException e) {
e.printStackTrace();
return null;
}catch(Exception e) {
e.printStackTrace();
return null;
}finally {
try {
if(rs!=null)rs.close();
//删除所有选修了该老师所教授课程的选课记录
public boolean deleteRecord(String tid) {
Connection connection=null;
PreparedStatement pstmt=null;
int row;
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="delete from choosecourse where cId in (select cId from course where tId=?)";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, tid); //替换上面的?
row=pstmt.executeUpdate();
if(row>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();
int row;
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="insert into choosecourse(sId,cId,grade) values(?,?,?)";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, score.getsId()); //替换上面第一个?
pstmt.setString(2, score.getcId()); //替换上面第二个?
pstmt.setFloat(3, Float.parseFloat(score.getGrade()));
row=pstmt.executeUpdate(); //返回增加数据的条数(这里是返回1)
if(row>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 studentDao.updateBySid(sid,pass);
}
else {
return false;
}
}
//学生课程退选 及 该课程“已选人数”减1
public boolean courseDelete(String sid,String cid) {
if(studentDao.isExistRecord(sid,cid)) { //选修记录存在
return studentDao.courseDelete(sid,cid) & studentDao.cutCourseNum(cid);
}
else {
return false;
}
}
//增加学生选课记录 及 该课程“已选人数”加1
public boolean addChooseCourse(Score score) {
//选修记录不存在 和 可选人数>0 才能增加
String cName=request.getParameter("cName");
String tId=request.getParameter("tId");
String credit=request.getParameter("credit");
String period=request.getParameter("period");
String cPlace=request.getParameter("cPlace");
String cNumAll=request.getParameter("cNumAll");
String cNum=request.getParameter("cNum");
String dId=request.getParameter("dId");
Course course=new Course(cId,cName,tId,credit,period,cPlace,cNumAll,cNum,dId); //封装到实体类
AdminService adminService=new AdminService();
boolean result=adminService.addCourse(course);
//PrintWriter out=response.getWriter();
/*if(result) {
out.println("注册成功!");