0
点赞
收藏
分享

微信扫一扫

基于JSP+Servlet学生在线选课系统(管理员、教师、学生)

开发工具:eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

	
	//学生课程退选 及 该课程“已选人数”减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 才能增加
		if(!studentDao. isExistRecord(score.getsId(),score.getcId())) {
			if(studentDao.surplusCount(score.getcId())>0) {	//	=0:系统异常和可选人数为0
				return studentDao.addChooseCourse(score) & studentDao.addCourseNum(score.getcId());
			}
			else {
				return false;
			}
		}
			connection=con.getConnection();
			String sql="select cId,cName,credit,period,cPlace,cNumAll,cNum,tName from course,teacher where course.tId=teacher.tId";
			pstmt=connection.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()) {	
				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 cnumall=rs.getString("cNumAll");
				String cnum=rs.getString("cNum");
				String tname=rs.getString("tName");
				course=new Course(cid,cname,credit,period,cplace,cnumall,cnum,tname);
				courses.add(course);
			}
			return courses;
		}catch(ClassNotFoundException e) {
					e.printStackTrace();
				}		
			}
		}	
		
		//根据教师号删除教师详细信息
		public boolean deleteTeadetailByTid(String tid) {
			Connection connection=null;
			PreparedStatement pstmt=null;
			int row;
			try{
				DBUtil con=new DBUtil();
				connection=con.getConnection();
				String sql="delete from teadetail where tId=?";
				pstmt=connection.prepareStatement(sql);
				pstmt.setString(1, tid);	//替换上面的?
				row=pstmt.executeUpdate();
				if(row>0) {
					return true;
				}
				else {
					return false;
				}
			}catch(ClassNotFoundException e) {
								<li>
								<a href="addstudent.jsp">添加学生</a><hr>
								</li>
								<li>
								<a href="addteacher.jsp">添加老师</a><hr>
								</li>
								<li>
								<a href="AllStuQueryServlet">查询学生</a><hr>
								</li>
								<li>
								<a href="AllTeaQueryServlet">查询老师</a><hr>
								</li>
								<li>
		}catch(ClassNotFoundException e) {
			e.printStackTrace();
			return false;
		}catch(SQLException e) {
			e.printStackTrace();
			return false;
		}catch(Exception e) {
			e.printStackTrace();
			return false;
		}finally {
			try {
		}catch(ClassNotFoundException e) {
			e.printStackTrace();
			return false;
		}catch(SQLException e) {
			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();
			}		
		}
	}

	#middle{
		display:table;
		table-layout:fixed;
		
		margin-top:0;
		width:100%;
		heigth:950px;
	}
	#nav-wrapper{
		margin-top: 2px;
		padding: 0.75em;
		background-color:#87CEFA;
		border-right: 1px solid #bbb;
		border-bottom: 1px solid #bbb;
		font-size: 10pt;
		border-bottom-right-radius: 0px;
		box-shadow: 0 0 5px #aaa;
					e.printStackTrace();
				}		
			}
		}
		public boolean isExistAid(String aid) {//true:此人存在	 false:此人不存在
			return queryByAid(aid)==null? false:true;
		}
		public Admin queryByAid(String aid) {
			Connection connection=null;
			PreparedStatement pstmt=null;
			ResultSet rs=null;
			Admin admin=null;
			try{
				DBUtil con=new DBUtil();
				connection=con.getConnection();
				String sql="select * from admin where aId=?";
				pstmt=connection.prepareStatement(sql);
			connection=con.getConnection();
			String sql="delete from choosecourse where sId=?";
			pstmt=connection.prepareStatement(sql);
			pstmt.setString(1, sid);	//替换上面的?
			row=pstmt.executeUpdate();
			if(row>0) {
				return true;
			}
			else {
				return false;
				try {
					if(rs!=null)rs.close();
					if(pstmt!=null)pstmt.close();
					if(connection!=null)connection.close();
				}catch(SQLException e) {
					e.printStackTrace();
				}		
			}
		}
		//增加学生
		public boolean addStudent(Student student1) {
			Connection connection=null;
			PreparedStatement pstmt=null;
			int row;
			try{
				DBUtil con=new DBUtil();
				connection=con.getConnection();
  border-collapse: collapse;
  text-align: left;
}
	#middle > div { display: table-row; }
	#middle > div > div { display: table-cell; vertical-align: top; }

	#mainLeft {
	  width: 190px;
	  transition: width 0.4s;
	  height:400px;
	  padding-left: 7px;
	  padding-top:20px;
											<td align="center"><%=course.getPeriod() %></td>
											<td align="center"><%=course.getcPlace() %></td>
											<td align="center"><%=course.getcNum() %></td>
											
										</tr>		
						<%
									}
						%>
								</table>
						<% 
							}catch(Exception e){
								e.printStackTrace();
							}
						%>
					</div>
					</nav>
					</div>
				</div>
			</div>
		</main>
	</div>
</body>
		  text-decoration: none;
		  color: #444;
		}
		#mainRight {
		  padding-left: 14px;
		  padding-right: 15px;
		  padding-top:20px;
		  text-indent: 0.6em;

		}
		#ind{
			color:#8B4513;
		}
		#hea{
			color:white;
		}
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>开课</title>
<style type="text/css">
body, input {
  font-family: 'Open Sans', sans-serif;
  font-size: 10.5pt;
}
table {
  border-collapse: collapse;
  text-align: left;
}
	#middle > div { display: table-row; }
	#middle > div > div { display: table-cell; vertical-align: top; }

	#mainLeft {
	  width: 190px;
	  transition: width 0.4s;
	  padding-left: 7px;
							<%
										while (iter.hasNext()) {
											Course course = iter.next();
							%>
											<tr>
												<td height="30" bgcolor="wheat"><%=course.getcName()%></td>
												<td height="30" bgcolor="beige"><%=course.getCredit()%></td>
												<td height="30" bgcolor="wheat"><%=course.getPeriod()%></td>
												<td height="30" bgcolor="beige"><%=course.getcPlace()%></td>
												<td height="30" bgcolor="wheat"><%=course.gettName()%></td>
												<td height="30" bgcolor="beige">
												<a href="StuCourseDelServlet?sid=<%=(String) session.getAttribute("id")%>&cid=<%=course.getcId()%>">退选</a></td>
											</tr>
							<%
										}
							%>
									</table>
							<%
								} catch (Exception e) {
									e.printStackTrace();
								}
							%>
						</div>
		}
		#mainRight {
		  padding-left: 14px;
		  padding-right: 15px;
		  padding-top:20px;
		  text-indent: 0.6em;

		}
		#ind{
			color:#4169E1;
		}
		#hea{
	/**
	 * @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);
	}

}
package com.demo.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
		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("注册成功!");
			response.sendRedirect("StudentQueryAllServlet");
		}
		else {
			out.println("注册失败,该学生已存在,请检查学号是否正确!");
		}*/
		if(!result) {	//注册失败
			request.setAttribute("error", "addError");
		}
		else {	//注册成功
		margin-top:0;
		width:100%;
		heigth:950px;
	}
	#nav-wrapper{
		margin-top: 2px;
		padding: 0.75em;
		background-color:#87CEFA;
		border-right: 1px solid #bbb;
		border-bottom: 1px solid #bbb;
		font-size: 10pt;
		border-bottom-right-radius: 0px;
		box-shadow: 0 0 5px #aaa;
		heigth:400px;
	}
	#nav-wrapper1{
		margin-top: 2px;
		padding: 0.75em;
		background-color:#ADD8E6;
			PreparedStatement pstmt=null;
			ResultSet rs=null;
			Teacher teacher=null;
			try{
				DBUtil con=new DBUtil();
				connection=con.getConnection();
				String sql="select teacher.*,teadetail.* from teacher,teadetail where teacher.tId=teadetail.tId and teacher.tId=?";
				pstmt=connection.prepareStatement(sql);
				pstmt.setString(1, tid);	//替换上面的?
				rs=pstmt.executeQuery();
				if(rs.next()) {	//只有一条数据,不用循环		
	}

}
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.demo.vo.Course"%>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>选课查询及其退选</title>
<style type="text/css">
	td{text-align:center}
</style>
<style type="text/css">
body, input {
		border-bottom-right-radius: 0px;
		box-shadow: 0 0 5px #aaa;
		heigth:400px;
	}
	#nav-wrapper1{
		margin-top: 2px;
		padding: 0.75em;
		background-color:#ADD8E6;
		border-left: 1px solid #bbb;
		border-bottom: 1px solid #bbb;
		font-size: 10pt;
		border-bottom-left-radius: 0px;
		box-shadow: 0 0 5px #aaa;
		heigth:500px;
	}
	#mainLeft h2 {
		  margin-bottom: 0.2em;
		  font-size: 1.2em;
		}
	public void settPass(String tPass) {
		this.tPass = tPass;
	}
	public String getdId() {
		return dId;
	}
	public void setdId(String dId) {
		this.dId = dId;
	}
	public String gettSex() {
		return tSex;
	}
	public void settSex(String tSex) {
		this.tSex = tSex;
	}
	public String gettAge() {
		return tAge;
	}
								<li>
								<a href="StuCourseQueryServlet?sid=<%=(String)session.getAttribute("id")%>">选课查询以及退选</a><hr>
								</li>
								<li>
								<a href="StuAllCourseQueryServlet">选课</a><hr>
								</li>
								<li>
								<a href="StuDeleteServlet?sid=<%=(String)session.getAttribute("id")%>">注销</a><hr>
								</li>
							</ul>
							<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
							</div>
						</nav>
					</div>
				</div>
				<div id="mainRight">
					<div id="nav-wrapper1">
					<nav>
					String name=rs.getString("sName");
					String pass=rs.getString("sPass");
					String did=rs.getString("dId");
					String sex=rs.getString("sSex");
					String mobil=rs.getString("sMobil");
					String adr=rs.getString("sAddress");	
					student=new Student(id,name,pass,did,sex,mobil,adr);
					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 {
				}		
			}
		} 
		
		//删除所有选修了该老师所教授课程的选课记录
		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;
				}

适用

课程设计,大作业,毕业设计,项目练习,学习演示等


运行环境

Java≥8、Tomcat≥7.0、MySQL≥5.5

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

技术框架

CSS JavaScript JSP Servlet JDBC MySQL

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

管理员:个人信息、学生、老师、学生、课程等管理

教师:个人信息、成绩、选课管理、教室查看

学生:个人信息、成绩查看、选课和查看

eclipse或MyEclipse或idea

20220319010250

20220319010249

管理员

20220319010243

20220319010244

20220319010245

20220319010246

20220319010247

20220319010248

学生

20220319010231

20220319010232

20220319010233

20220319010234

20220319010235

20220319010236

20220319010237

教师

20220319010238

20220319010239

20220319010240

20220319010241

20220319010242


举报

相关推荐

基于SpringBoot学生选课系统

0 条评论