测试具体要求:
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发布:
要求可以实现在浏览器直接访问系统。
如有错误敬请指正
系统简单解释:
1.创建学生或教师的时候id和初始密码一致
2.在程序中使用cookie 来传递参数(emmm 目前只是简单运用)
3.对于身份的判定是在每一个账号后边加status 状态判定
1 为学生 2为教师 3 为管理员
4.对于选课存储时储存在了学生表的class 中,存储类型为课程编号,用String类型进行拼接,查询时进行模糊查询
5.对于选课的人数限制没有完善。
使用jar 包:
数据库建表如下:
代码实现:
com.Bean 类
1 packagecom.Bean;2
3 public classclasses {4 privateString name;5 privateString teacher;6 privateString pid;7 privateString number;8 privateString count;9
10 publicclasses(String name, String teacher, String pid, String number) {11 super();12 this.name =name;13 this.teacher =teacher;14 this.pid =pid;15 this.number =number;16 }17 publicclasses(String name, String teacher, String pid, String number, String count) {18 super();19 this.name =name;20 this.teacher =teacher;21 this.pid =pid;22 this.number =number;23 this.count =count;24 }25 publicString getCount() {26 returncount;27 }28 public voidsetCount(String count) {29 this.count =count;30 }31 publicString getName() {32 returnname;33 }34 publicString getNumber() {35 returnnumber;36 }37 public voidsetNumber(String number) {38 this.number =number;39 }40 public voidsetName(String name) {41 this.name =name;42 }43 publicString getTeacher() {44 returnteacher;45 }46 public voidsetTeacher(String teacher) {47 this.teacher =teacher;48 }49 publicString getPid() {50 returnpid;51 }52 public voidsetPid(String pid) {53 this.pid =pid;54 }55
56 }
1 packagecom.Bean;2
3 public classpremission {4
5 privateString name;6 privateString pwd;7
8 publicString getName() {9 returnname;10 }11 public voidsetName(String name) {12 this.name =name;13 }14 publicString getPwd() {15 returnpwd;16 }17 public voidsetPwd(String pwd) {18 this.pwd =pwd;19 }20
21
22
23 }
1 packagecom.Bean;2
3 public classstudent {4 privateString id;5 privateString name;6 privateString sex;7 privateString classes;8 privateString zhuanye;9 publicString getId() {10 returnid;11 }12 publicstudent(String id, String name, String sex, String classes, String zhuanye) {13 super();14 this.id =id;15 this.name =name;16 this.sex =sex;17 this.classes =classes;18 this.zhuanye =zhuanye;19 }20 public voidsetId(String id) {21 this.id =id;22 }23 publicString getName() {24 returnname;25 }26 public voidsetName(String name) {27 this.name =name;28 }29 publicString getSex() {30 returnsex;31 }32 public voidsetSex(String sex) {33 this.sex =sex;34 }35 publicString getClasses() {36 returnclasses;37 }38 public voidsetClasses(String classes) {39 this.classes =classes;40 }41 publicString getZhuanye() {42 returnzhuanye;43 }44 public voidsetZhuanye(String zhuanye) {45 this.zhuanye =zhuanye;46 }47
48
49 }
1 packagecom.Bean;2
3 public classteacher {4
5 privateString id;6 privateString name;7 privateString sex;8 privateString xueyuan;9 privateString zhicheng;10 publicString getId() {11 returnid;12 }13 public voidsetId(String id) {14 this.id =id;15 }16 publicString getName() {17 returnname;18 }19 public voidsetName(String name) {20 this.name =name;21 }22 publicString getSex() {23 returnsex;24 }25 public voidsetSex(String sex) {26 this.sex =sex;27 }28 publicString getXueyuan() {29 returnxueyuan;30 }31 public voidsetXueyuan(String xueyuan) {32 this.xueyuan =xueyuan;33 }34 publicString getZhicheng() {35 returnzhicheng;36 }37 public voidsetZhicheng(String zhicheng) {38 this.zhicheng =zhicheng;39 }40 publicteacher(String id, String name, String sex, String xueyuan, String zhicheng) {41 super();42 this.id =id;43 this.name =name;44 this.sex =sex;45 this.xueyuan =xueyuan;46 this.zhicheng =zhicheng;47 }48
49
50 }
com.DBUtil类:基础链接
1 packagecom.DBUtil;2 /**
3 * 测试时主要要导入jar4 */
5
6 importjava.beans.Statement;7 importjava.sql.Connection;8 importjava.sql.DriverManager;9 importjava.sql.PreparedStatement;10 importjava.sql.ResultSet;11 importjava.sql.SQLException;12
13 /**
14 * 建立数据库连接15 *@authorcuixingyu16 *17 */
18 public classDBUtil {19 //连接数据库 url路径和用户名 密码
20 public static String db_url="jdbc:mysql://localhost:3306/db_database01?serverTimezone=UTC&characterEncoding=UTF-8&useSSL=false";21 public static String db_user="root";22 public static String db_password="101032";23 public staticConnection getConn() {24 Connection conn=null;25 try{26 //数据库驱动加载
27 Class.forName("com.mysql.cj.jdbc.Driver");28 try{29 //链接数据库
30 conn=DriverManager.getConnection(db_url, db_user, db_password);31 } catch(SQLException e) {32 //TODO Auto-generated catch block
33 e.printStackTrace();34 }35 System.out.println("驱动链接加载成功!");36 } catch(ClassNotFoundException e) {37 //TODO Auto-generated catch block
38 e.printStackTrace();39 }40 //返回链接
41 returnconn;42
43 }44
45 //关闭函数
46 public static voidclose(Statement state,Connection conn) {47 //只有状态和连接时,先关闭状态
48 if(state!=null) {49 try{50 ((Connection) state).close();51 } catch(SQLException e) {52 //TODO Auto-generated catch block
53 e.printStackTrace();54 }55
56
57 }58 if(conn!=null) {59 try{60 conn.close();61 } catch(SQLException e) {62 //TODO Auto-generated catch block
63 e.printStackTrace();64 }65 }66 }67 //关闭函数
68 public static voidclose(PreparedStatement state,Connection conn) {69 if(state!=null) {70 try{71 ((Connection) state).close();72 } catch(SQLException e) {73 //TODO Auto-generated catch block
74 e.printStackTrace();75 }76
77 }78 if(conn!=null) {79 try{80 conn.close();81 } catch(SQLException e) {82 //TODO Auto-generated catch block
83 e.printStackTrace();84 }85 }86 }87
88 public static voidclose(ResultSet rs,Statement state,Connection conn) {89 if(rs!=null) {90 try{91 rs.close();92 } catch(SQLException e) {93 //TODO Auto-generated catch block
94 e.printStackTrace();95 }96 }97 if(state!=null) {98 try{99 ((Connection) state).close();100 } catch(SQLException e) {101 //TODO Auto-generated catch block
102 e.printStackTrace();103 }104 }105 if(conn!=null) {106 try{107 conn.close();108 } catch(SQLException e) {109 //TODO Auto-generated catch block
110 e.printStackTrace();111 }112 }113 }114
115 //关闭函数
116 public static voidclose(java.sql.Statement state, Connection conn) {117 //TODO Auto-generated method stub
118 if(state!=null)119 {120 try{121 state.close();122 } catch(SQLException e) {123 //TODO Auto-generated catch block
124 e.printStackTrace();125 }126 }127 if(conn!=null) {128 try{129 conn.close();130 } catch(SQLException e) {131 //TODO Auto-generated catch block
132 e.printStackTrace();133 }134 }135 }136 //测试主函数 利用Java运行来测试
137 @SuppressWarnings("static-access")138 public static void main(String[] args) throwsSQLException {139 DBUtil dbu=newDBUtil();140 dbu.getConn();141 }142 }
com.Dao 类
1 packagecom.Dao;2
3 importjava.sql.Connection;4 importjava.sql.ResultSet;5 importjava.sql.SQLException;6 importjava.sql.Statement;7 importjava.util.ArrayList;8 importjava.util.List;9
10 importcom.Bean.classes;11 importcom.Bean.student;12 importcom.Bean.teacher;13 importcom.DBUtil.DBUtil;14
15 public classDao {16 //获取登陆用户的身份信息
17 public intlogin(String username, String password) {18
19 Connection conn =DBUtil.getConn();20 Statement state =null;21 ResultSet rs = null;22 int flag=0;23 String sql = "select * from login where name='"+username+"' and pwd = '"+password+"'";24 try{25 state =conn.createStatement();26 } catch(SQLException e) {27 //TODO Auto-generated catch block
28 e.printStackTrace();29 }30
31 try{32 rs=state.executeQuery(sql);33 } catch(SQLException e) {34 //TODO Auto-generated catch block
35 e.printStackTrace();36 }37
38 try{39 while(rs.next()) {40 flag=rs.getInt("status");41 }42 } catch(SQLException e) {43 //TODO Auto-generated catch block
44 e.printStackTrace();45 }46 returnflag;47 }48 //在学生界面添加学生信息 --- 未读题
49 public void addstudent(String id, String name, String sex, String classes, String zhuanye) throwsException {50 Connection conn =DBUtil.getConn();51 Statement state =null;52 ResultSet rs = null;53 String sql="insert into student(pid,name,sex,classes,zhuanye) values('"+id+"','"+name+"','"+sex+"','"+classes+"','"+zhuanye+"')";54 state =conn.createStatement();55 state.executeUpdate(sql);56 DBUtil.close(state, conn);57 }58 //遍历所有的课程
59 public Listsearchclasses() {60
61 //构建遍历函数
62 Listlist =new ArrayList<>();63 //建立数据库链接
64 Connection conn=DBUtil.getConn();65 //sql 语句 查询
66 String sql="select * from classes";67 Statement pstmt = null;68 try{69 //执行sql语句
70 pstmt =conn.createStatement();71 ResultSet rs=pstmt.executeQuery(sql);72 classes use=null;73 while(rs.next()) {74 //遍历获取的信息
75 String name=rs.getString("name");76 String teacher=rs.getString("teacher");77 String id=rs.getString("pid");78 String number=rs.getString("number");79 String count=rs.getString("count");80
81 use=newclasses(name,teacher,id,number,count);82 list.add(use);83 }84 } catch(SQLException e) {85 //TODO Auto-generated catch block
86 e.printStackTrace();87 }88 finally{89 DBUtil.close(pstmt, conn);90 }91
92 returnlist;93 }94 //增设新课程
95 public void addclasses(String name, String teacher, String pid, String number,String count) throwsSQLException {96 Connection conn =DBUtil.getConn();97 Statement state =null;98 String sql="insert into classes(name,teacher,pid,number,count) values('"+name+"','"+teacher+"','"+pid+"','"+number+"','"+count+"')";99 state =conn.createStatement();100 state.executeUpdate(sql);101 DBUtil.close(state, conn);102
103
104 }105 //遍历学生的信息
106 public static ArrayList getstudent(String pid) throwsException{107 ArrayListlist =new ArrayList<>();108 Connection conn=DBUtil.getConn();109 Statement pstmt = null;110 String sql="select * from student where pid = '"+pid+"'";111 pstmt =conn.createStatement();112 ResultSet rs=pstmt.executeQuery(sql);113 student student=null;114 while(rs.next()) {115 //遍历获取的信息
116 String id=rs.getString("pid");117 String name=rs.getString("name");118 String sex=rs.getString("sex");119 String classes=rs.getString("classes");120 String zy=rs.getString("zhuanye");121 student=newstudent(id,name,sex,classes,zy);122 list.add(student);123 System.out.println(id);124 System.out.println(name);125 System.out.println(sex);126 System.out.println(classes);127 System.out.println(zy);128 }129 returnlist;130
131 }132 //遍历教师的信息
133 public static ArrayList getteacher(String pid) throwsException{134 ArrayListlist =new ArrayList<>();135 Connection conn=DBUtil.getConn();136 Statement pstmt = null;137 String sql="select * from teacher where pid = '"+pid+"'";138 pstmt =conn.createStatement();139 ResultSet rs=pstmt.executeQuery(sql);140 teacher teacher=null;141 while(rs.next()) {142 //遍历获取的信息
143 String id=rs.getString("pid");144 String name=rs.getString("name");145 String sex=rs.getString("sex");146 String xy=rs.getString("xueyuan");147 String zc=rs.getString("zhicheng");148 teacher=newteacher(id,name,sex,xy,zc);149 list.add(teacher);150 System.out.println(id);151 System.out.println(name);152 System.out.println(sex);153 System.out.println(xy);154 System.out.println(zc);155 }156 returnlist;157
158 }159
160
161
162
163
164
165 //修改学生的个人信息 但是jsp学号不允许修改 在这里当作修改的索引
166 public void updatestudent(String id, String name, String sex, String classes, String zhuanye) throwsException {167 Connection conn =DBUtil.getConn();168 Statement state =null;169 String sql="update student set name='"+name+"',sex='"+sex+"',classes='"+classes+"',zhuanye='"+zhuanye+"' where pid='"+id+"' ";170 state=conn.createStatement();171 state.executeUpdate(sql);172
173 DBUtil.close(state, conn);174 }175 //修改教师个人信息
176 public void updateteacher(String id, String name, String sex, String xueyuan, String zhicheng) throwsException {177 Connection conn =DBUtil.getConn();178 Statement state =null;179 String sql="update teacher set name='"+name+"',sex='"+sex+"',xueyuan='"+xueyuan+"',zhicheng='"+zhicheng+"' where pid='"+id+"' ";180 state=conn.createStatement();181 state.executeUpdate(sql);182 System.out.println("更新");183 DBUtil.close(state, conn);184
185 }186
187 public void addteacher(String id, String name, String sex, String classes, String zhuanye) throwsException {188 Connection conn =DBUtil.getConn();189 Statement state =null;190 String sql="insert into teacher(pid,name,sex,xueyuan,zhicheng) values('"+id+"','"+name+"','"+sex+"','"+classes+"','"+zhuanye+"')";191 state =conn.createStatement();192 state.executeUpdate(sql);193 DBUtil.close(state, conn);194
195 }196
197 public void loginteacher(String id) throwsException {198 Connection conn =DBUtil.getConn();199 Statement state =null;200 String sql="insert into login(name,pwd,status) values('"+id+"','"+id+"','"+2+"')";201 state =conn.createStatement();202 state.executeUpdate(sql);203 DBUtil.close(state, conn);204
205 }206
207 public void loginstudent(String id) throwsException {208 Connection conn =DBUtil.getConn();209 Statement state =null;210 String sql="insert into login(name,pwd,status) values('"+id+"','"+id+"','"+1+"')";211 state =conn.createStatement();212 state.executeUpdate(sql);213 DBUtil.close(state, conn);214
215 }216 //选课
217 public static void addclass(String name,String studentid,String id) throwsException {218 Connection conn =DBUtil.getConn();219 Statement state =null;220 //给记录课程的数据库做标记
221 String sql="select * from classes where name = '"+name+"'";222 state =conn.createStatement();223 ResultSet rs=state.executeQuery(sql);224 int count=0;225 String a=null;226 //获取已经选取该课程的人数
227 while(rs.next()) {228 a=rs.getString("count");229 }230 //将人数加一
231 count=Integer.parseInt(a);232 count++;233 a=Integer.toString(count);234 //更新选课人数
235 String sql1="update classes set count='"+count+"' where name='"+name+"' ";236 state.executeUpdate(sql1);237 //获取选课学生的先前选课情况
238 String sql2="select * from student where pid = '"+studentid+"'";239 String kecheng=null;240 state =conn.createStatement();241 ResultSet rs1=state.executeQuery(sql2);242
243 while(rs1.next()) {244 kecheng=rs1.getString("class");245 }246 //添加一个新的编号
247 kecheng=kecheng+","+id;248 //给选课的学生做标记 记录学生的选课信息 在学生的数据库内记录
249 String sql3="update student set class='"+kecheng+"' where pid='"+studentid+"' ";250 state.executeUpdate(sql3);251 DBUtil.close(state, conn);252 }253 //通过姓名查询教师信息 不准确
254 public static List getteachers(String names) throwsException{255 ArrayListlist =new ArrayList<>();256 Connection conn=DBUtil.getConn();257 Statement pstmt = null;258 String sql="select * from teacher where name = '"+names+"'";259 pstmt =conn.createStatement();260 ResultSet rs=pstmt.executeQuery(sql);261 teacher teacher=null;262 while(rs.next()) {263 //遍历获取的信息
264 String id=rs.getString("pid");265 String name=rs.getString("name");266 String sex=rs.getString("sex");267 String xy=rs.getString("xueyuan");268 String zc=rs.getString("zhicheng");269 teacher=newteacher(id,name,sex,xy,zc);270 list.add(teacher);271 System.out.println("查看教师信息");272 }273 returnlist;274
275 }276 //查询教师开设的课程
277 public static List getclass(String names) throwsException {278 //TODO Auto-generated method stub
279
280 List list=new ArrayList<>();281 Connection conn =DBUtil.getConn();282 Statement state =null;283 String sql="select * from classes where teacher like '%"+names+"%'";284 state =conn.createStatement();285 ResultSet rs=state.executeQuery(sql);286 classes cs=null;287 while(rs.next()) {288 String name=rs.getString("name");289 String teacher=rs.getString("teacher");290 String id=rs.getString("pid");291 String number=rs.getString("number");292 String count=rs.getString("count");293 cs=newclasses(name,teacher,id,number,count);294 list.add(cs);295 System.out.println("教师查询选课结果");296 }297 returnlist;298 }299 //获取学生信息 通过id查找
300 public static List getstudents(String id) throwsException {301 List list=new ArrayList<>();302 Connection conn =DBUtil.getConn();303 Statement state =null;304 //模糊查询
305 String sql="select * from student where class like '%"+id+"%'";306 state =conn.createStatement();307 ResultSet rs=state.executeQuery(sql);308 student s=null;309 while(rs.next()) {310 String pid=rs.getString("pid");311 String name=rs.getString("name");312 String sex=rs.getString("sex");313 String classes=rs.getString("classes");314 String zy=rs.getString("zhuanye");315 s=newstudent(pid,name,sex,classes,zy);316 list.add(s);317 }318 returnlist;319 }320
321
322
323 }
com.Servlet 类:学生 教师 管理员 登陆
1 packagecom.Servlet;2
3 importjava.io.IOException;4 importjava.io.UnsupportedEncodingException;5
6 importjavax.servlet.ServletException;7 importjavax.servlet.annotation.WebServlet;8 importjavax.servlet.http.HttpServlet;9 importjavax.servlet.http.HttpServletRequest;10 importjavax.servlet.http.HttpServletResponse;11
12 importcom.Dao.Dao;13
14 /**
15 * Servlet implementation class adminServlet16 */
17 @WebServlet("/adminServlet")18 public class adminServlet extendsHttpServlet {19 private static final long serialVersionUID = 1L;20
21 protected void service(HttpServletRequest req,HttpServletResponse resp)throwsServletException,IOException22 {23 req.setCharacterEncoding("UTF-8");24
25 String method = req.getParameter("method");26 if(method.equals("addstudent"))27 {28 try{29 addstudent(req,resp);30 } catch(Exception e) {31 //TODO Auto-generated catch block
32 e.printStackTrace();33 }34 }35
36 if(method.equals("addteacher"))37 {38 try{39 addteacher(req,resp);40 } catch(Exception e) {41 //TODO Auto-generated catch block
42 e.printStackTrace();43 }44 }45 }46 //添加教师信息
47 private void addteacher(HttpServletRequest req, HttpServletResponse resp) throwsException {48
49
50 req.setCharacterEncoding("UTF-8");51
52 String id = req.getParameter("id");53 String name = req.getParameter("name");54 String sex = req.getParameter("sex");55 String classes = req.getParameter("classes");56 String zhuanye = req.getParameter("zhicheng");57
58 Dao dao=newDao();59 System.out.println(zhuanye);60 dao.addteacher(id,name,sex,classes,zhuanye);61 dao.loginteacher(id);62 //添加完成重新刷新界面
63 req.getRequestDispatcher("addteacher.jsp").forward(req, resp);64 }65 //添加学生信息
66 private void addstudent(HttpServletRequest req, HttpServletResponse resp) throwsException {67 //TODO Auto-generated method stub
68
69 req.setCharacterEncoding("UTF-8");70
71 String id = req.getParameter("id");72 String name = req.getParameter("name");73 String sex = req.getParameter("sex");74 String classes = req.getParameter("classes");75 String zhuanye = req.getParameter("zhuanye");76
77 Dao dao=newDao();78 dao.addstudent(id,name,sex,classes,zhuanye);79 dao.loginstudent(id);80 //跳转到新的界面
81 req.getRequestDispatcher("addstudent.jsp").forward(req, resp);82 }83
84 }
1 packagecom.Servlet;2 /*
3 * 登陆界面调用的Servlet4 */
5
6 importjava.io.IOException;7 importjava.io.UnsupportedEncodingException;8
9 importjavax.servlet.ServletException;10 importjavax.servlet.annotation.WebServlet;11 importjavax.servlet.http.Cookie;12 importjavax.servlet.http.HttpServlet;13 importjavax.servlet.http.HttpServletRequest;14 importjavax.servlet.http.HttpServletResponse;15
16 importcom.Bean.premission;17 importcom.Dao.Dao;18
19 /**
20 * Servlet implementation class LoginServlet21 */
22 @WebServlet("/LoginServlet")23 public class LoginServlet extendsHttpServlet {24 private static final long serialVersionUID = 1L;25
26 protected void service(HttpServletRequest req,HttpServletResponse resp)throwsServletException,IOException27 {28 req.setCharacterEncoding("UTF-8");29
30 String method = req.getParameter("method");31 if(method.equals("login"))32 {33 login(req,resp);34 }35 }36
37 private void login(HttpServletRequest req, HttpServletResponse resp) throwsServletException, IOException {38 //TODO Auto-generated method stub
39 try{40 req.setCharacterEncoding("UTF-8");41 } catch(UnsupportedEncodingException e) {42 //TODO Auto-generated catch block
43 e.printStackTrace();44 }45 String username = req.getParameter("user");46 String password = req.getParameter("password");47 System.out.println(username);48 System.out.println(password);49 premission p=newpremission();50 p.setName(username);51 p.setPwd(password);52 Dao dao=newDao();53 //获取登陆账号的身份权限信息
54 int status=dao.login(username,password);55 //通过状态来跳转不同界面
56 if(status==1) {57 System.out.println("学生");58 //设置cookie 作为边的参数
59 Cookie cookie=new Cookie("student", username);60 cookie.setPath("/");61 //设置存活时间
62 cookie.setMaxAge(60*60*24);63 resp.addCookie(cookie);64 req.getRequestDispatcher("student.jsp").forward(req, resp);65 }else if(status==2) {66 System.out.println("老师");67 //设置cookie 作为边的参数
68 Cookie cookie=new Cookie("teacher", username);69 cookie.setPath("/");70 //设置存活时间
71 cookie.setMaxAge(60*60*24);72 resp.addCookie(cookie);73 req.getRequestDispatcher("teacher.jsp").forward(req, resp);74 }else if(status==3) {75 System.out.println("管理员");76 //设置cookie 作为边的参数
77 req.getRequestDispatcher("admin.jsp").forward(req, resp);78 }else if(status==0) {79 System.out.println("错误");80 req.getRequestDispatcher("error.jsp").forward(req, resp);81 }82
83 }84
85 }
1 packagecom.Servlet;2
3 importjava.io.IOException;4 importjava.io.UnsupportedEncodingException;5 importjava.util.List;6
7 importjavax.servlet.ServletException;8 importjavax.servlet.annotation.WebServlet;9 importjavax.servlet.http.HttpServlet;10 importjavax.servlet.http.HttpServletRequest;11 importjavax.servlet.http.HttpServletResponse;12
13 importcom.Bean.classes;14 importcom.Dao.Dao;15
16 /**
17 * Servlet implementation class StudentServlet18 */
19 @WebServlet("/StudentServlet")20 public class StudentServlet extendsHttpServlet {21 private static final long serialVersionUID = 1L;22
23 protected void service(HttpServletRequest req,HttpServletResponse resp)throwsServletException,IOException24 {25 req.setCharacterEncoding("UTF-8");26
27 String method = req.getParameter("method");28 if(method.equals("add"))29 {30 try{31 add(req,resp);32 } catch(Exception e) {33 //TODO Auto-generated catch block
34 e.printStackTrace();35 }36 }37 if(method.equals("show"))38 {39 try{40 show(req,resp);41 } catch(Exception e) {42 //TODO Auto-generated catch block
43 e.printStackTrace();44 }45 }46
47 if(method.equals("update"))48 {49 try{50 update(req,resp);51 } catch(Exception e) {52 //TODO Auto-generated catch block
53 e.printStackTrace();54 }55 }56
57 if(method.equals("addclasses")) {58 try{59 addclass(req,resp);60 } catch(Exception e) {61 //TODO Auto-generated catch block
62 e.printStackTrace();63 }64 }65
66 }67 //选课
68 private void addclass(HttpServletRequest req, HttpServletResponse resp) throwsException {69 req.setCharacterEncoding("UTF-8");70 String name=req.getParameter("name");71 String studentid=req.getParameter("studentid");72 String id=req.getParameter("id");73 Dao.addclass(name,studentid,id);74 req.getRequestDispatcher("show.jsp").forward(req, resp);75 }76 //修改学生信息
77 private void update(HttpServletRequest req, HttpServletResponse resp) throwsException {78
79 req.setCharacterEncoding("UTF-8");80 String id = req.getParameter("id");81 String name = req.getParameter("name");82 String sex = req.getParameter("sex");83 String classes = req.getParameter("classes");84 String zhuanye = req.getParameter("zhuanye");85 Dao dao=newDao();86 dao.updatestudent(id,name,sex,classes,zhuanye);87 req.getRequestDispatcher("update1.jsp").forward(req, resp);88
89
90 }91 //展示所有的课程
92 private void show(HttpServletRequest req, HttpServletResponse resp) throwsServletException, IOException {93 //TODO Auto-generated method stub
94 req.setCharacterEncoding("UTF-8");95
96 Dao dao=newDao();97 List list=dao.searchclasses();98 req.setAttribute("list", list);99 req.getRequestDispatcher("show.jsp").forward(req, resp);100 }101 //添加学生信息
102 private void add(HttpServletRequest req, HttpServletResponse resp) throwsException {103 //TODO Auto-generated method stub
104 try{105 req.setCharacterEncoding("UTF-8");106 } catch(UnsupportedEncodingException e) {107 //TODO Auto-generated catch block
108 e.printStackTrace();109 }110 String id = req.getParameter("id");111 String name = req.getParameter("name");112 String sex = req.getParameter("sex");113 String classes = req.getParameter("classes");114 String zhuanye = req.getParameter("zhuanye");115
116 System.out.println(id);117 System.out.println(name);118 System.out.println(sex);119 System.out.println(classes);120 System.out.println(zhuanye);121 Dao dao=newDao();122
123
124 dao.addstudent(id,name,sex,classes,zhuanye);125
126 //req.getRequestDispatcher("student.jsp").forward(req, resp);
127
128
129 }130
131 }
1 packagecom.Servlet;2
3 importjava.io.IOException;4 importjava.io.UnsupportedEncodingException;5 importjava.sql.SQLException;6 importjava.util.List;7
8 importjavax.servlet.ServletException;9 importjavax.servlet.annotation.WebServlet;10 importjavax.servlet.http.HttpServlet;11 importjavax.servlet.http.HttpServletRequest;12 importjavax.servlet.http.HttpServletResponse;13
14 importcom.Bean.classes;15 importcom.Bean.student;16 importcom.Bean.teacher;17 importcom.Dao.Dao;18
19 /**
20 * Servlet implementation class TeacherServlet21 */
22 @WebServlet("/TeacherServlet")23 public class TeacherServlet extendsHttpServlet {24 private static final long serialVersionUID = 1L;25
26 protected void service(HttpServletRequest req,HttpServletResponse resp)throwsServletException,IOException27 {28 req.setCharacterEncoding("UTF-8");29
30 String method = req.getParameter("method");31 if(method.equals("add"))32 {33 try{34 add(req,resp);35 } catch(Exception e) {36 //TODO Auto-generated catch block
37 e.printStackTrace();38 }39 }40 if(method.equals("update"))41 {42 try{43 update(req,resp);44 } catch(Exception e) {45 //TODO Auto-generated catch block
46 e.printStackTrace();47 }48 }49 if(method.equals("seacrch")) {50 try{51 search(req,resp);52 } catch(Exception e) {53 //TODO Auto-generated catch block
54 e.printStackTrace();55 }56 }57
58 if(method.equals("searchclass")) {59 try{60 searchclass(req,resp);61 } catch(Exception e) {62 //TODO Auto-generated catch block
63 e.printStackTrace();64 }65 }66 if(method.equals("checkstudent")) {67 try{68 checkstudent(req,resp);69 } catch(Exception e) {70 //TODO Auto-generated catch block
71 e.printStackTrace();72 }73 }74
75 }76 //查询所选课程的学生信息
77 private void checkstudent(HttpServletRequest req, HttpServletResponse resp) throwsException {78 req.setCharacterEncoding("UTF-8");79 String id=req.getParameter("id");80 //获取课程编号 据此查找学生 模糊
81 Listlist =Dao.getstudents(id);82 req.setAttribute("list", list);83 req.getRequestDispatcher("showstudentinfo.jsp").forward(req, resp);84 }85 //教师查询学生选课结果
86 private void searchclass(HttpServletRequest req, HttpServletResponse resp) throwsException {87 req.setCharacterEncoding("UTF-8");88 String name=req.getParameter("name");89
90 List list=Dao.getclass(name);91 req.setAttribute("list", list);92 req.getRequestDispatcher("showselectclass.jsp").forward(req, resp);93 }94 //查询教师信息
95 private void search(HttpServletRequest req, HttpServletResponse resp) throwsException {96 req.setCharacterEncoding("UTF-8");97 String name=req.getParameter("name");98 List list=Dao.getteachers(name);99 req.setAttribute("list", list);100 req.getRequestDispatcher("showteacherinfo.jsp").forward(req, resp);101 }102 //修改教师个人信息
103 private void update(HttpServletRequest req, HttpServletResponse resp) throwsException {104 req.setCharacterEncoding("UTF-8");105 String id = req.getParameter("id");106 String name = req.getParameter("name");107 String sex = req.getParameter("sex");108 String xueyuan = req.getParameter("xueyuan");109 String zhicheng = req.getParameter("zhicheng");110 Dao dao=newDao();111 dao.updateteacher(id,name,sex,xueyuan,zhicheng);112 req.getRequestDispatcher("update2.jsp").forward(req, resp);113
114 }115 //添加新的课程
116 private void add(HttpServletRequest req, HttpServletResponse resp) throwsUnsupportedEncodingException, SQLException {117 //TODO Auto-generated method stub
118 req.setCharacterEncoding("UTF-8");119
120 String name = req.getParameter("name");121 String teacher= req.getParameter("teacher");122 String pid = req.getParameter("id");123 String number = req.getParameter("number");124 String count="0";125 Dao dao=newDao();126 dao.addclasses(name,teacher,pid,number,count);127 }128 }
jsp界面:
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
管理员添加学生8
9
10
11
12
13
14
15
16
17 学号
18
19
20
21 姓名
22
23
24
25 性别
26 男
27 女
28
29
30 班级
31
32
33
34
35 专业
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
1
2
3
4
5
6
7 pageEncoding="UTF-8"%>
8
9
10
11
12
教师添加新课程13
14
15
16 function onload()17 {18
19 Cookie[] cookies=request.getCookies();20 String value="";21 ArrayList list=new ArrayList<>();22 if(cookies!=null){23 System.out.println("cookie的长度为:"+cookies.length);24 for(int i=0;i
27 if(cookies[i].getName().equals("teacher"))28 {29 value=cookies[i].getValue();30 System.out.println(value+":");31 list=Dao.getteacher(value);32 }33 }34 }35 %>
36 }37
38
39
40
41
42
43
46 %>
47 课程名称
48
49
50
51 课程教师
52 >
53
54
55 课程人数
56
57
58
59 课程编号
60
61
62
63
64
65
66
67
68
69
70
71
72
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
管理员添加学生8
9
10
11
12
13
14
15
16 学号
17
18
19
20 姓名
21
22
23
24 性别
25 男
26 女
27
28
29 班级
30
31
32
33
34 专业
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
管理员添加教师8
9
10
11
12
13
14
15
16
17 工号
18
19
20
21 姓名
22
23
24
25 性别
26 男
27 女
28
29
30 学院
31
32
33
34
35 职称
36
37 教授
38 副教授
39 讲师
40 助教
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
课程信息管理系统:管理员界面8
9
10
11 .headframe{12 width:100%;13 height:130px;14 border:0;15 }16
17 .leftframe{18 float:left;19 width:250px;20 height:600px;21 border:0;22 }23
24 .mainframe{25 float:right;26 width:1200px;27 height:600px;28 border:0;29 }30
31
32
33
34
35
36
37
38
39
40
41
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
错误界面8
9
10 用户不存在或者用户密码错误11
12
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
标题头8
9
10 .headdiv{11 background-color:#3F51B5;12 width:100%;13 height:130px;14 }15
16 .headdiv P{17 font-family:YouYuan;18 font-size:20px;19 color:#E8EAF6;20 position:relative;21 left:20px;22 top:45px;23 }24
25 .headdiv a{26 font-family:YouYuan;27 font-size:20px;28 color:#E8EAF6;29
30 text-align:right;31 }32
33
34
35
36
37
38
39
43
44
45
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
8
9
10
11
12
登陆界面13
14
15 .colorcloth{16 background-color:#3399FF;17 width:100%;18 height:210px;19 }20
21 .container{22 background-color:#FFFFFF;23 width:400px;24 height:210px;25 margin:200px auto;26 }27
28 .buser{29 position:relative;30 left:30px;31 top:5px;32 border-radius:3px;33 width:210px;34 height:20px;35 border:#DCDCDC 1px solid;36 }37
38 .buser:hover{39 box-shadow:0 012px #1E90FF;40 }41
42 .bpassword{43 position:relative;44 left:45px;45 top:20px;46 border-radius:3px;47 width:210px;48 height:20px;49 border:#DCDCDC 1px solid;50 }51
52 .bpassword:hover{53 box-shadow:0 012px #1E90FF;54 }55
56 .user{57 position:relative;58 left:20px;59 top:5px;60 font-size:14px;61 font-family:STHeiti;62 font-weight:600;63 }64
65 .password{66 position:relative;67 left:35px;68 top:20px;69 font-size:14px;70 font-family:STHeiti;71 font-weight:600;72 }73
74 .butn{75 position:relative;76 left:77px;77 top:55px;78 width:215px;79 height:25px;80 border-radius:3px;81 color:white;82 background-color:#0066CC;83 text-align:center;84 text-decoration:none;85 border:none;86 }87
88 .butn:hover{89 box-shadow:0 010px #0066CC;90 }91
92 .title{93 background-color:#FFFFFF;94 width:100%;95 }96
97 .title p{98 font-family:YouYuan;99 font-size:90px;100 color:#0066CC;101 text-align:center;102 }103
104
105
106
107
108
课程信息登录
109
110
111
112
113
114
115
116 用户名
117
118
119 密码
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
学生左侧栏8
9
10 .leftMenu{11 background-color:#7986CB;12 width:250px;13 height:600px;14 position:relative;15 top:0px;16 }17
18 .menuParent{19 background-color:#BBDEFB;20 }21
22
23
24
25
26
27
28
29
49
50
51
52
53
54
55
56
57
58
1
2
3
4
5
6
7 pageEncoding="UTF-8"%>
8
9
10
11
12
教师左侧栏13
14
15 .leftMenu{16 background-color:#7986CB;17 width:250px;18 height:600px;19 position:relative;20 top:0px;21 }22
23 .menuParent{24 background-color:#BBDEFB;25 }26
27
28
29
30
31
32
33
34
35
36 functiononload()37 {38
39 Cookie[] cookies=request.getCookies();40 String value="";41 ArrayList list=new ArrayList<>();42 if(cookies!=null){43 System.out.println("cookie的长度为:"+cookies.length);44 for(int i=0;i
47 if(cookies[i].getName().equals("teacher"))48 {49 value=cookies[i].getValue();50 System.out.println(value+":");51 list=Dao.getteacher(value);52 }53 }54 }55 %>
56 }57
58
59
60
61
62
63
87
88
89
90
91
92
93
94
95
96
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
管理员左侧栏8
9
10 .leftMenu{11 background-color:#7986CB;12 width:250px;13 height:600px;14 position:relative;15 top:0px;16 }17
18 .menuParent{19 background-color:#BBDEFB;20 }21
22
23
24
25
26
27
28
29
48
49
50
51
52
53
54
55
56
57
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
显示界面8
9
10
11
12 显示界面
13
14
15
1
2
3
4
5
6
7 pageEncoding="utf-8"%>
8
9
10
11
12
13
课程浏览14
15
16 functiononload()17 {18
19 Cookie[] cookies=request.getCookies();20 String value="";21 ArrayList list=new ArrayList<>();22 if(cookies!=null){23 System.out.println("cookie的长度为:"+cookies.length);24 for(int i=0;i
27 if(cookies[i].getName().equals("student"))28 {29 value=cookies[i].getValue();30 System.out.println(value+":");31 list=Dao.getstudent(value);32 }33 }34 }35 %>
36 }37
38
39
40
课程信息浏览:
41
42
43
44
45
课程名称46
任课教师47
课程编号48
课程人数49
操作50
51
52
53
${item.name}54
${item.teacher}55
${item.pid}56
${item.number}57
60 %>
61
选课62
63
64
65
66
67
68
69
70
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
8
9
10
11
12
课程详细信息查询
13
14
15
课程名称16
任课教师17
课程编号18
课程人数19
选课人数20
21
22
${param.name}23
${param.teacher}24
${param.pid}25
${param.number}26
${param.count}27
28
29
30
31
32
1
2 pageEncoding="utf-8"%>
3
4
5
6
7
8
9
10
11
12
选课结果浏览:
13
14
15
16
17
课程名称18
已选课人数19
课程总人数20
21
22
23
24
${item.name}25
${item.count}26
${item.number}27
28
29
30
31
32
33
34
35
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
8
9
10
11
30
31
32
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
8
9
10
11
12
学生详细信息
13
14
15
学生学号16
学生姓名17
学生性别18
学生班级19
学生专业20
21
22
${param.id}23
${param.name}24
${param.sex}25
${param.classes}26
${param.zhuanye}27
28
29
30
31
32
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
8
9
10
11
12
教师信息浏览
13
14
15
16
教师工号17
教师姓名18
教师性别19
所在院系20
教师职称21
22
23
24
25
${item.id}26
${item.name}27
${item.sex}28
${item.xueyuan}29
${item.zhicheng}30
31
32
33
34
35
36
37
38
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
课程信息管理系统:学生界面8
9
10
11 .headframe{12 width:100%;13 height:130px;14 border:0;15 }16
17 .leftframe{18 float:left;19 width:250px;20 height:600px;21 border:0;22 }23
24 .mainframe{25 float:right;26 width:1200px;27 height:600px;28 border:0;29 }30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
1
2 pageEncoding="UTF-8"%>
3
4
5
6
7
课程信息管理系统:教师界面8
9
10
11 .headframe{12 width:100%;13 height:130px;14 border:0;15 }16
17 .leftframe{18 float:left;19 width:250px;20 height:600px;21 border:0;22 }23
24 .mainframe{25 float:right;26 width:1200px;27 height:600px;28 border:0;29 }30
31
32
33
34
35
36
37
38
39
40
41
1
2
3
4
5
6
7 pageEncoding="UTF-8"%>
8
9
10
11
12
修改学生信息13
14
15
16 /*.butn{*/
17 /*display:inline-block;*/
18 /*padding: 8px 35px;*/
19 /*background-color:#32CD32;*/
20 /*color:white;*/
21 /*border:none;*/
22 /*text-align:center;*/
23 /*text-decoration:none;*/
24 /*border-radius:5px;*/
25 /*position:absolute;*/
26 /*left:40px;*/
27 /*top:95px;*/
28 /*}*/
29
30
31
32
33
34 functiononload()35 {36
37 Cookie[] cookies=request.getCookies();38 String value="";39 ArrayList list=new ArrayList<>();40 if(cookies!=null){41 System.out.println("cookie的长度为:"+cookies.length);42 for(int i=0;i
45 if(cookies[i].getName().equals("student"))46 {47 value=cookies[i].getValue();48 System.out.println(value+":");49 list=Dao.getstudent(value);50 }51 }52 }53 %>
54 }55
56
57
58
59
60
61
64 %>
65
66 学号
67 >
68
69
70 姓名
71 >
72
73
74 性别
75 男
76 女
77
78
79
80
81 班级
82 >
83
84
85
86 专业
87 >
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
1
2
3
4
5
6
7 pageEncoding="UTF-8"%>
8
9
10
11
12
修改教师信息13
14
15
16 /*.butn{*/
17 /*display:inline-block;*/
18 /*padding: 8px 35px;*/
19 /*background-color:#32CD32;*/
20 /*color:white;*/
21 /*border:none;*/
22 /*text-align:center;*/
23 /*text-decoration:none;*/
24 /*border-radius:5px;*/
25 /*position:absolute;*/
26 /*left:40px;*/
27 /*top:95px;*/
28 /*}*/
29
30
31
32 functiononload()33 {34
35 Cookie[] cookies=request.getCookies();36 String value="";37 ArrayList list=new ArrayList<>();38 if(cookies!=null){39 System.out.println("cookie的长度为:"+cookies.length);40 for(int i=0;i
43 if(cookies[i].getName().equals("teacher"))44 {45 value=cookies[i].getValue();46 System.out.println(value+":");47 list=Dao.getteacher(value);48 }49 }50 }51 %>
52 }53
54
55
56
57
58
59
60
61
64 %>
65 工号
66 >
67
68
69 姓名
70 >
71
72
73 性别
74 男
75 女
76
77
78 学院
79 >
80
81
82
83 职称
84 >
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
登陆界面:
操作界面:
学生:
老师:
管理员: