石家庄铁道大学选课管理系统1
石家庄铁道大学选课管理系统
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发布:
要求可以实现在浏览器直接访问系统。
Bean层
lesson
package Bean; public class lesson { private String bianhao; private String name; private String num; private String teacher; public String getBianhao() { return bianhao; } public void setBianhao(String bianhao) { this.bianhao = bianhao; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getNum() { return num; } public void setNum(String num) { this.num = num; } public String getTeacher() { return teacher; } public void setTeacher(String teacher) { this.teacher = teacher; } }
student
package Bean; public class student{ private int id; private String sid; private String sname; private String ssex; private String classid; private String zhuanye; public String getSid() { return sid; } public void setSid(String sid) { this.sid = sid; } public String getName() { return sname; } public void setName(String name) { this.sname = sname; } public String getSex() { return ssex; } public void setSex(String sex) { this.ssex = ssex; } public String getClassid() { return classid; } public void setClassid(String classid) { this.classid = classid; } public String getZhuanye() { return zhuanye; } public void setZhuanye(String zhuanye) { this.zhuanye = zhuanye; } public int getId() { return id; } public void setId(int id) { this.id = id; } }
teacher
public class teacher { private int id; private String tid; private String tname; private String tsex; private String xueyuan; private String zhicheng; public String getTid() { return tid; } public void setTid(String id) { this.tid = tid; } public String getName() { return tname; } public void setName(String tname) { this.tname = tname; } public String getSex() { return tsex; } public void setSex(String tsex) { this.tsex = tsex; } public String getXueyuan() { return xueyuan; } public void setXueyuan(String xueyuan) { this.xueyuan = xueyuan; } public String getZhicheng() { return zhicheng; } public void setZhicheng(String zhicheng) { this.zhicheng = zhicheng; } public int getId() { return id; } public void setId(int id) { this.id = id; } }
user
package Bean; public class User { private String profession; private String username; private String password; public String getProfession() { return profession; } public void setProfession(String profession) { this.profession = profession; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
Dao层
package Dao; import Bean.lesson; import Bean.student; import Bean.teacher; import Util.Util; import org.jetbrains.annotations.NotNull; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class dao { public static void addStudent(@NotNull student student) { String sql="insert into student(sid,sname,ssex,classid,zhuanye) " + "values('"+student.getSid()+','+student.getName()+"','"+student.getSex()+"','"+student.getClassid()+"','"+student.getZhuanye()+"')"; Connection connection=Util.getConnection(); try { Statement statement=connection.createStatement(); statement.executeUpdate(sql); Util.close(null,statement,connection); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void addTeacher(teacher teacher) { String sql="insert into teacher(tid,tname,tsex,xueyuan,zhicheng) " + "values('"+teacher.getTid()+','+teacher.getName()+"','"+teacher.getSex()+"','"+teacher.getXueyuan()+"','"+teacher.getZhicheng()+"')"; Connection connection=Util.getConnection(); try { Statement statement=connection.createStatement(); statement.executeUpdate(sql); Util.close(null,statement,connection); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void addLesson(@NotNull lesson lesson) { String sql = "insert into lesson(bianhao,cname,num,teacher) " + "values('" + lesson.getBianhao() + ',' +lesson.getName() + "','" + lesson.getNum() + "','" + lesson.getTeacher() + "')"; Connection connection = Util.getConnection(); try { Statement statement = connection.createStatement(); statement.executeUpdate(sql); Util.close(null, statement, connection); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void updateStudent(student student) { //锟睫革拷学锟斤拷 String sql="update student set sname='"+student.getName()+"',ssex='"+student.getSex()+"'," + "sid='"+student.getId()+"',zhuanye='"+student.getZhuanye()+"',classid='"+student.getClassid()+"' " + "where sid="+student.getId(); Connection connection=Util.getConnection(); try { Statement statement=connection.createStatement(); statement.executeUpdate(sql); Util.close(null,statement,connection); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static student getStudent(int id) { student student=new student(); Connection connection=Util.getConnection(); ResultSet rs=null; String sql="select * from student where id="+id; try { Statement statement=connection.createStatement(); rs=statement.executeQuery(sql); if(rs.next()) { student.setSid(rs.getString("sid")); student.setClassid(rs.getString("classid")); student.setZhuanye(rs.getString("zhaunye")); student.setName(rs.getString("sname")); student.setSex(rs.getString("ssex")); } Util.close(rs,statement,connection); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return student; } public static teacher getTeacher(int id) { teacher teacher=new teacher(); Connection connection=Util.getConnection(); ResultSet rs=null; String sql="select * from teacher where id="+id; try { Statement statement=connection.createStatement(); rs=statement.executeQuery(sql); if(rs.next()) { teacher.setTid(rs.getString("tid")); teacher.setXueyuan(rs.getString("xueyuan")); teacher.setZhicheng(rs.getString("zhicheng")); teacher.setName(rs.getString("tname")); teacher.setSex(rs.getString("tsex")); } Util.close(rs,statement,connection); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return teacher; } }
servlet
package Dao; import java.io.IOException; import java.sql.SQLException; 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 Bean.lesson; import Bean.student; import Bean.teacher; import org.jetbrains.annotations.NotNull; /** * Servlet implementation class servlet */ @WebServlet("/servlet") public class servlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public servlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(@NotNull HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //response.getWriter().append("Served at: ").append(request.getContextPath()); request.setCharacterEncoding("utf-8"); String method=request.getParameter("method"); if(method.equals("add")){ try { add(request,response); } catch (ServletException | IOException | SQLException e) { e.printStackTrace(); } } } public void add(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws ServletException, IOException, SQLException { student student = new student(); teacher teacher = new teacher(); lesson lesson = new lesson(); student.setSid(request.getParameter("sid")); student.setZhuanye(request.getParameter("zhuanye")); student.setName(request.getParameter("sname")); student.setSex(request.getParameter("ssex")); teacher.setTid(request.getParameter("tid")); teacher.setXueyuan(request.getParameter("xueyuan")); teacher.setName(request.getParameter("tname")); teacher.setSex(request.getParameter("tsex")); teacher.setZhicheng(request.getParameter("zhicheng")); lesson.setName(request.getParameter("cid")); lesson.setBianhao(request.getParameter("bianhao")); lesson.setNum(request.getParameter("num")); lesson.setTeacher(request.getParameter("teacher")); dao.addStudent(student); dao.addLesson(lesson); dao.addTeacher(teacher); try { response.sendRedirect("index.jsp"); } catch (IOException e) { // TODO 鑷姩鐢熸垚鐨� catch 鍧� e.printStackTrace(); } } /** * @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); }