测试具体要求:
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 package com.Bean; 2 3 public class classes { 4 private String name; 5 private String teacher; 6 private String pid; 7 private String number; 8 private String count; 9 10 public classes(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 public classes(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 public String getCount() { 26 return count; 27 } 28 public void setCount(String count) { 29 this.count = count; 30 } 31 public String getName() { 32 return name; 33 } 34 public String getNumber() { 35 return number; 36 } 37 public void setNumber(String number) { 38 this.number = number; 39 } 40 public void setName(String name) { 41 this.name = name; 42 } 43 public String getTeacher() { 44 return teacher; 45 } 46 public void setTeacher(String teacher) { 47 this.teacher = teacher; 48 } 49 public String getPid() { 50 return pid; 51 } 52 public void setPid(String pid) { 53 this.pid = pid; 54 } 55 56 }
1 package com.Bean; 2 3 public class premission { 4 5 private String name; 6 private String pwd; 7 8 public String getName() { 9 return name; 10 } 11 public void setName(String name) { 12 this.name = name; 13 } 14 public String getPwd() { 15 return pwd; 16 } 17 public void setPwd(String pwd) { 18 this.pwd = pwd; 19 } 20 21 22 23 }
1 package com.Bean; 2 3 public class student { 4 private String id; 5 private String name; 6 private String sex; 7 private String classes; 8 private String zhuanye; 9 public String getId() { 10 return id; 11 } 12 public student(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 void setId(String id) { 21 this.id = id; 22 } 23 public String getName() { 24 return name; 25 } 26 public void setName(String name) { 27 this.name = name; 28 } 29 public String getSex() { 30 return sex; 31 } 32 public void setSex(String sex) { 33 this.sex = sex; 34 } 35 public String getClasses() { 36 return classes; 37 } 38 public void setClasses(String classes) { 39 this.classes = classes; 40 } 41 public String getZhuanye() { 42 return zhuanye; 43 } 44 public void setZhuanye(String zhuanye) { 45 this.zhuanye = zhuanye; 46 } 47 48 49 }
1 package com.Bean; 2 3 public class teacher { 4 5 private String id; 6 private String name; 7 private String sex; 8 private String xueyuan; 9 private String zhicheng; 10 public String getId() { 11 return id; 12 } 13 public void setId(String id) { 14 this.id = id; 15 } 16 public String getName() { 17 return name; 18 } 19 public void setName(String name) { 20 this.name = name; 21 } 22 public String getSex() { 23 return sex; 24 } 25 public void setSex(String sex) { 26 this.sex = sex; 27 } 28 public String getXueyuan() { 29 return xueyuan; 30 } 31 public void setXueyuan(String xueyuan) { 32 this.xueyuan = xueyuan; 33 } 34 public String getZhicheng() { 35 return zhicheng; 36 } 37 public void setZhicheng(String zhicheng) { 38 this.zhicheng = zhicheng; 39 } 40 public teacher(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 package com.DBUtil; 2 /** 3 * 测试时主要要导入jar 4 */ 5 6 import java.beans.Statement; 7 import java.sql.Connection; 8 import java.sql.DriverManager; 9 import java.sql.PreparedStatement; 10 import java.sql.ResultSet; 11 import java.sql.SQLException; 12 13 /** 14 * 建立数据库连接 15 * @author cuixingyu 16 * 17 */ 18 public class DBUtil { 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 static Connection 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 return conn; 42 43 } 44 45 //关闭函数 46 public static void close(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 void close(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 void close(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 void close(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) throws SQLException { 139 DBUtil dbu=new DBUtil(); 140 dbu.getConn(); 141 } 142 }
com.Dao 类
1 package com.Dao; 2 3 import java.sql.Connection; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 import java.sql.Statement; 7 import java.util.ArrayList; 8 import java.util.List; 9 10 import com.Bean.classes; 11 import com.Bean.student; 12 import com.Bean.teacher; 13 import com.DBUtil.DBUtil; 14 15 public class Dao { 16 //获取登陆用户的身份信息 17 public int login(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 return flag; 47 } 48 //在学生界面添加学生信息 --- 未读题 49 public void addstudent(String id, String name, String sex, String classes, String zhuanye) throws Exception { 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 List<classes> searchclasses() { 60 61 //构建遍历函数 62 List<classes>list =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=new classes(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 return list; 93 } 94 //增设新课程 95 public void addclasses(String name, String teacher, String pid, String number,String count) throws SQLException { 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<student> getstudent(String pid) throws Exception{ 107 ArrayList<student>list =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=new student(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 return list; 130 131 } 132 //遍历教师的信息 133 public static ArrayList<teacher> getteacher(String pid) throws Exception{ 134 ArrayList<teacher>list =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=new teacher(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 return list; 157 158 } 159 160 161 162 163 164 165 //修改学生的个人信息 但是jsp学号不允许修改 在这里当作修改的索引 166 public void updatestudent(String id, String name, String sex, String classes, String zhuanye) throws Exception { 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) throws Exception { 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) throws Exception { 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) throws Exception { 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) throws Exception { 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) throws Exception { 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<teacher> getteachers(String names) throws Exception{ 255 ArrayList<teacher>list =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=new teacher(id,name,sex,xy,zc); 270 list.add(teacher); 271 System.out.println("查看教师信息"); 272 } 273 return list; 274 275 } 276 //查询教师开设的课程 277 public static List<classes> getclass(String names) throws Exception { 278 // TODO Auto-generated method stub 279 280 List<classes> 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=new classes(name,teacher,id,number,count); 294 list.add(cs); 295 System.out.println("教师查询选课结果"); 296 } 297 return list; 298 } 299 //获取学生信息 通过id查找 300 public static List<student> getstudents(String id) throws Exception { 301 List<student> 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=new student(pid,name,sex,classes,zy); 316 list.add(s); 317 } 318 return list; 319 } 320 321 322 323 }
com.Servlet 类:学生 教师 管理员 登陆
1 package com.Servlet; 2 3 import java.io.IOException; 4 import java.io.UnsupportedEncodingException; 5 6 import javax.servlet.ServletException; 7 import javax.servlet.annotation.WebServlet; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 import com.Dao.Dao; 13 14 /** 15 * Servlet implementation class adminServlet 16 */ 17 @WebServlet("/adminServlet") 18 public class adminServlet extends HttpServlet { 19 private static final long serialVersionUID = 1L; 20 21 protected void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException 22 { 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) throws Exception { 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=new Dao(); 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) throws Exception { 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=new Dao(); 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 package com.Servlet; 2 /* 3 * 登陆界面调用的Servlet 4 */ 5 6 import java.io.IOException; 7 import java.io.UnsupportedEncodingException; 8 9 import javax.servlet.ServletException; 10 import javax.servlet.annotation.WebServlet; 11 import javax.servlet.http.Cookie; 12 import javax.servlet.http.HttpServlet; 13 import javax.servlet.http.HttpServletRequest; 14 import javax.servlet.http.HttpServletResponse; 15 16 import com.Bean.premission; 17 import com.Dao.Dao; 18 19 /** 20 * Servlet implementation class LoginServlet 21 */ 22 @WebServlet("/LoginServlet") 23 public class LoginServlet extends HttpServlet { 24 private static final long serialVersionUID = 1L; 25 26 protected void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException 27 { 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) throws ServletException, 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=new premission(); 50 p.setName(username); 51 p.setPwd(password); 52 Dao dao=new Dao(); 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 package com.Servlet; 2 3 import java.io.IOException; 4 import java.io.UnsupportedEncodingException; 5 import java.util.List; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.annotation.WebServlet; 9 import javax.servlet.http.HttpServlet; 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 13 import com.Bean.classes; 14 import com.Dao.Dao; 15 16 /** 17 * Servlet implementation class StudentServlet 18 */ 19 @WebServlet("/StudentServlet") 20 public class StudentServlet extends HttpServlet { 21 private static final long serialVersionUID = 1L; 22 23 protected void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException 24 { 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) throws Exception { 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) throws Exception { 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=new Dao(); 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) throws ServletException, IOException { 93 // TODO Auto-generated method stub 94 req.setCharacterEncoding("UTF-8"); 95 96 Dao dao=new Dao(); 97 List<classes> 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) throws Exception { 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=new Dao(); 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 package com.Servlet; 2 3 import java.io.IOException; 4 import java.io.UnsupportedEncodingException; 5 import java.sql.SQLException; 6 import java.util.List; 7 8 import javax.servlet.ServletException; 9 import javax.servlet.annotation.WebServlet; 10 import javax.servlet.http.HttpServlet; 11 import javax.servlet.http.HttpServletRequest; 12 import javax.servlet.http.HttpServletResponse; 13 14 import com.Bean.classes; 15 import com.Bean.student; 16 import com.Bean.teacher; 17 import com.Dao.Dao; 18 19 /** 20 * Servlet implementation class TeacherServlet 21 */ 22 @WebServlet("/TeacherServlet") 23 public class TeacherServlet extends HttpServlet { 24 private static final long serialVersionUID = 1L; 25 26 protected void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException 27 { 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) throws Exception { 78 req.setCharacterEncoding("UTF-8"); 79 String id=req.getParameter("id"); 80 //获取课程编号 据此查找学生 模糊 81 List<student>list =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) throws Exception { 87 req.setCharacterEncoding("UTF-8"); 88 String name=req.getParameter("name"); 89 90 List<classes> 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) throws Exception { 96 req.setCharacterEncoding("UTF-8"); 97 String name=req.getParameter("name"); 98 List<teacher> 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) throws Exception { 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=new Dao(); 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) throws UnsupportedEncodingException, 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=new Dao(); 126 dao.addclasses(name,teacher,pid,number,count); 127 } 128 }
jsp界面:
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>管理员添加学生</title> 8 9 10 11 </head> 12 <body> 13 14 <div class="container"> 15 <section> 16 <form action="StudentServlet?method=add" method="post" onsubmit="return check()"> 17 <span class="cname">学号</span> 18 <input type="text" name="id" class="icname" placeholder=" class-name" id="id"> 19 <br/> 20 21 <span class="teacher">姓名</span> 22 <input type="text" name="name" class="iteacher" placeholder=" teacher" id="name"> 23 <br/> 24 25 <span class="place">性别</span> 26 <label><input type="radio" name="sex" id="sex" value="男">男</label> 27 <label><input type="radio" name="sex" id="sex" value="女">女</label> 28 <br/> 29 30 <span class="place">班级</span> 31 <input type="text" name="classes" class="iteacher" placeholder=" teacher" id="classes"> 32 <br/> 33 34 35 <span class="place">专业</span> 36 <input type="text" name="zhuanye" class="iteacher" placeholder=" teacher" id="zhuanye"> 37 <br/> 38 39 <input type="submit" value="保存" class="butn"> 40 <br/> 41 </form> 42 </section> 43 </div> 44 45 <script type="text/javascript"> 46 47 48 </script> 49 50 </body> 51 </html>
1 <%@page import="com.Dao.*"%> 2 <%@page import="com.Bean.*"%> 3 <%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%> 4 <%@page import="java.util.ArrayList"%> 5 <%@page import="java.util.List" %> 6 <%@ page language="java" contentType="text/html; charset=UTF-8" 7 pageEncoding="UTF-8"%> 8 <!DOCTYPE html> 9 <html> 10 <head> 11 <meta charset="UTF-8"> 12 <title>教师添加新课程</title> 13 14 </head> 15 <script type="text/javascript"> 16 function onload() 17 { 18 <% 19 Cookie[] cookies=request.getCookies(); 20 String value=""; 21 ArrayList<teacher> list=new ArrayList<>(); 22 if(cookies!=null){ 23 System.out.println("cookie的长度为:"+cookies.length); 24 for(int i=0;i<cookies.length;i++) 25 { 26 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 </script> 38 <body> 39 40 <div class="container"> 41 <section> 42 <form action="TeacherServlet?method=add" method="post" onsubmit="return check()"> 43 <%for(teacher s:list) 44 { 45 46 %> 47 <span class="cname">课程名称</span> 48 <input type="text" name="name" class="icname" placeholder=" class-name" id="name"> 49 <br/> 50 51 <span class="teacher">课程教师</span> 52 <input type="text" name="teacher" class="iteacher" readonly="readonly" placeholder=" teacher" id="teacher" value=<%=s.getName() %>> 53 <br/> 54 <% } %> 55 <span class="place">课程人数</span> 56 <input type="text" name="number" class="iplace" placeholder=" number" id="number"> 57 <br/> 58 59 <span class="place">课程编号</span> 60 <input type="text" name="id" class="iplace" placeholder=" class-id" id="id"> 61 <br/> 62 63 <input type="submit" value="保 存" class="butn"> 64 <br/> 65 </form> 66 </section> 67 </div> 68 69 70 71 </body> 72 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>管理员添加学生</title> 8 9 10 </head> 11 <body> 12 13 <div class="container"> 14 <section> 15 <form action="adminServlet?method=addstudent" method="post" onsubmit="return check()"> 16 <span class="cname">学号</span> 17 <input type="text" name="id" class="icname" placeholder=" xuehao" id="id"> 18 <br/> 19 20 <span class="teacher">姓名</span> 21 <input type="text" name="name" class="iteacher" placeholder=" name" id="name"> 22 <br/> 23 24 <span class="place">性别</span> 25 <label><input type="radio" name="sex" id="sex" value="男">男</label> 26 <label><input type="radio" name="sex" id="sex" value="女">女</label> 27 <br/> 28 29 <span class="place">班级</span> 30 <input type="text" name="classes" class="iteacher" placeholder=" banji" id="classes"> 31 <br/> 32 33 34 <span class="place">专业</span> 35 <input type="text" name="zhuanye" class="iteacher" placeholder=" zhuanye" id="zhuanye"> 36 <br/> 37 38 <input type="submit" value="保存" class="butn"> 39 <br/> 40 </form> 41 </section> 42 </div> 43 44 <script type="text/javascript"> 45 46 47 </script> 48 49 </body> 50 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>管理员添加教师</title> 8 9 10 11 </head> 12 <body> 13 14 <div class="container"> 15 <section> 16 <form action="adminServlet?method=addteacher" method="post" onsubmit="return check()"> 17 <span class="cname">工号</span> 18 <input type="text" name="id" class="icname" placeholder=" id" id="id"> 19 <br/> 20 21 <span class="teacher">姓名</span> 22 <input type="text" name="name" class="iteacher" placeholder=" name" id="name"> 23 <br/> 24 25 <span class="place">性别</span> 26 <label><input type="radio" name="sex" id="sex" value="男">男</label> 27 <label><input type="radio" name="sex" id="sex" value="女">女</label> 28 <br/> 29 30 <span class="place">学院</span> 31 <input type="text" name="classes" class="iteacher" placeholder=" xueyuan" id="classes"> 32 <br/> 33 34 35 <span class="place">职称</span> 36 <select name="zhicheng" id="zhicheng"> 37 <option value="教授">教授</option> 38 <option value="副教授">副教授</option> 39 <option value="讲师">讲师</option> 40 <option value="助教">助教</option> 41 </select> 42 <br/> 43 44 <input type="submit" value="保存" class="butn"> 45 <br/> 46 </form> 47 </section> 48 </div> 49 50 <script type="text/javascript"> 51 52 53 </script> 54 55 </body> 56 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>课程信息管理系统:管理员界面</title> 8 9 <style type="text/css"> 10 11 .headframe{ 12 100%; 13 height:130px; 14 border:0; 15 } 16 17 .leftframe{ 18 float:left; 19 250px; 20 height:600px; 21 border:0; 22 } 23 24 .mainframe{ 25 float:right; 26 1200px; 27 height:600px; 28 border:0; 29 } 30 31 </style> 32 33 </head> 34 35 36 <iframe src="head.jsp" class="headframe" scrolling="no"></iframe> 37 <iframe src="left3.jsp" class="leftframe" scrolling="no"></iframe> 38 <iframe src="main.jsp" name="mainAction" class="mainframe"></iframe> 39 40 41 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>错误界面</title> 8 </head> 9 <body> 10 用户不存在或者用户密码错误 11 </body> 12 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>标题头</title> 8 <style type="text/css"> 9 10 .headdiv{ 11 background-color:#3F51B5; 12 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 </style> 34 35 36 </head> 37 <body> 38 39 <div class="headdiv"> 40 <p>课程信息管理 </p> <br> 41   <a href="index.jsp" target="_top">退出</a> 42 </div> 43 44 </body> 45 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 5 <%@page import="com.Servlet.*"%> 6 <%@page import="com.Bean.*"%> 7 <%@page import="com.DBUtil.*"%> 8 <%@page import="com.Dao.*"%> 9 <html> 10 <head> 11 <meta charset="UTF-8"> 12 <title>登陆界面</title> 13 <style type="text/css"> 14 15 .colorcloth{ 16 background-color:#3399FF; 17 100%; 18 height:210px; 19 } 20 21 .container{ 22 background-color:#FFFFFF; 23 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 210px; 34 height:20px; 35 border:#DCDCDC 1px solid; 36 } 37 38 .buser:hover{ 39 box-shadow:0 0 12px #1E90FF; 40 } 41 42 .bpassword{ 43 position:relative; 44 left:45px; 45 top:20px; 46 border-radius:3px; 47 210px; 48 height:20px; 49 border:#DCDCDC 1px solid; 50 } 51 52 .bpassword:hover{ 53 box-shadow:0 0 12px #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 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 0 10px #0066CC; 90 } 91 92 .title{ 93 background-color:#FFFFFF; 94 100%; 95 } 96 97 .title p{ 98 font-family:YouYuan; 99 font-size:90px; 100 color:#0066CC; 101 text-align:center; 102 } 103 104 </style> 105 </head> 106 <body> 107 <div class="title"> 108 <p>课程信息登录</p> 109 </div> 110 111 <div class="colorcloth"> 112 <div class="container"> 113 <section> 114 <form action="LoginServlet?method=login" method="post"> 115 116 <span class="user">用户名</span> 117 <input type="text" name="user" class="buser" placeholder=" Usename"> 118 <br/> 119 <span class="password">密码</span> 120 <input type="password" name="password" class="bpassword" placeholder=" Password"> 121 <br/> 122 <input type="submit" value="登录" class="butn"> 123 <br/> 124 </form> 125 </section> 126 </div> 127 </div> 128 129 <script type="text/javascript"> 130 131 132 </script> 133 134 </body> 135 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>学生左侧栏</title> 8 <style type="text/css"> 9 10 .leftMenu{ 11 background-color:#7986CB; 12 250px; 13 height:600px; 14 position:relative; 15 top:0px; 16 } 17 18 .menuParent{ 19 background-color:#BBDEFB; 20 } 21 22 23 24 </style> 25 </head> 26 <body> 27 28 <div class="leftMenu"> 29 <div class="menu"> 30 31 32 <div class="menuParent"> 33 <div class="ListTitlePanel"> 34 <div class="ListTitle"> 35 <strong>课程信息管理</strong> 36 <div class="leftbgbt"></div> 37 </div> 38 </div> 39 40 <div class="menuList"> 41 <!-- <div><a target="mainAction" href="add1.jsp">添加个人信息</a></div> --> 42 <div><a target="mainAction" href="update1.jsp">修改个人信息</a></div> 43 <div><a target="mainAction" href="StudentServlet?method=show">浏览课程信息</a></div> 44 </div> 45 </div> 46 47 48 </div> 49 </div> 50 51 <script type="text/javascript"> 52 53 54 55 </script> 56 57 </body> 58 </html>
1 <%@page import="com.Dao.*"%> 2 <%@page import="com.Bean.*"%> 3 <%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%> 4 <%@page import="java.util.ArrayList"%> 5 <%@page import="java.util.List" %> 6 <%@ page language="java" contentType="text/html; charset=UTF-8" 7 pageEncoding="UTF-8"%> 8 <!DOCTYPE html> 9 <html> 10 <head> 11 <meta charset="UTF-8"> 12 <title>教师左侧栏</title> 13 <style type="text/css"> 14 15 .leftMenu{ 16 background-color:#7986CB; 17 250px; 18 height:600px; 19 position:relative; 20 top:0px; 21 } 22 23 .menuParent{ 24 background-color:#BBDEFB; 25 } 26 27 28 29 30 </style> 31 32 33 </head> 34 <script type="text/javascript"> 35 36 function onload() 37 { 38 <% 39 Cookie[] cookies=request.getCookies(); 40 String value=""; 41 ArrayList<teacher> list=new ArrayList<>(); 42 if(cookies!=null){ 43 System.out.println("cookie的长度为:"+cookies.length); 44 for(int i=0;i<cookies.length;i++) 45 { 46 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 </script> 59 <body onload="onload()"> 60 61 <div class="leftMenu"> 62 63 <div class="menu"> 64 65 66 <div class="menuParent"> 67 <div class="ListTitlePanel"> 68 <div class="ListTitle"> 69 <strong>课程信息管理</strong> 70 <div class="leftbgbt"></div> 71 </div> 72 </div> 73 <%for(teacher s:list) 74 { 75 76 %> 77 <div class="menuList"> 78 <div><a target="mainAction" href="add2.jsp">添加课程信息</a></div> 79 <div><a target="mainAction" href="update2.jsp">修改个人信息</a></div> 80 <div><a target="mainAction" href="TeacherServlet?method=searchclass&name=<%=s.getName() %>">浏览选课信息</a></div> 81 </div> 82 <% } %> 83 </div> 84 85 86 </div> 87 </div> 88 89 <script type="text/javascript"> 90 91 92 93 </script> 94 95 </body> 96 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>管理员左侧栏</title> 8 <style type="text/css"> 9 10 .leftMenu{ 11 background-color:#7986CB; 12 250px; 13 height:600px; 14 position:relative; 15 top:0px; 16 } 17 18 .menuParent{ 19 background-color:#BBDEFB; 20 } 21 22 23 24 </style> 25 </head> 26 <body> 27 28 <div class="leftMenu"> 29 <div class="menu"> 30 31 32 <div class="menuParent"> 33 <div class="ListTitlePanel"> 34 <div class="ListTitle"> 35 <strong>课程信息管理</strong> 36 <div class="leftbgbt"></div> 37 </div> 38 </div> 39 40 <div class="menuList"> 41 <div><a target="mainAction" href="addstudent.jsp">添加学生</a></div> 42 <div><a target="mainAction" href="addteacher.jsp">添加教师</a></div> 43 </div> 44 </div> 45 46 47 </div> 48 </div> 49 50 <script type="text/javascript"> 51 52 53 54 </script> 55 56 </body> 57 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>显示界面</title> 8 </head> 9 <body> 10 11 <div align="left"> 12 <font style="background-color: blue">显示界面 </font> 13 </div> 14 </body> 15 </html>
1 <%@page import="com.Dao.*"%> 2 <%@page import="com.Bean.*"%> 3 <%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%> 4 <%@page import="java.util.ArrayList"%> 5 <%@page import="java.util.List" %> 6 <%@ page language="java" contentType="text/html; charset=utf-8" 7 pageEncoding="utf-8"%> 8 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 9 <!DOCTYPE html> 10 <html> 11 <head> 12 <meta charset="utf-8"> 13 <title>课程浏览</title> 14 </head> 15 <script type="text/javascript"> 16 function onload() 17 { 18 <% 19 Cookie[] cookies=request.getCookies(); 20 String value=""; 21 ArrayList<student> list=new ArrayList<>(); 22 if(cookies!=null){ 23 System.out.println("cookie的长度为:"+cookies.length); 24 for(int i=0;i<cookies.length;i++) 25 { 26 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 </script > 38 <body onload="onload()"> 39 <div align="center"> 40 <h1>课程信息浏览:</h1> 41 42 <form action="StudentServlet?method=show" method="post" onsubmit="return check()"> 43 <table> 44 <tr> 45 <td>课程名称</td> 46 <td>任课教师</td> 47 <td>课程编号</td> 48 <td>课程人数</td> 49 <td align="center" colspan="1">操作</td> 50 </tr> 51 <c:forEach items="${list}" var="item"> 52 <tr> 53 <td><a href="showclassinfo.jsp?name=${item.name}&teacher=${item.teacher}&pid=${item.pid}&number=${item.number}&count=${item.count}">${item.name}</a></td> 54 <td><a href="TeacherServlet?method=seacrch&name=${item.teacher}">${item.teacher}</a></td> 55 <td>${item.pid}</td> 56 <td>${item.number}</td> 57 <%for(student s:list) 58 { 59 60 %> 61 <td><a href="StudentServlet?method=addclasses&name=${item.name}&studentid=<%=s.getId() %>&id=${item.pid}">选课</a></td> 62 <% } %> 63 </tr> 64 </c:forEach> 65 </table> 66 </form> 67 </div> 68 69 </body> 70 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title></title> 8 </head> 9 <body> 10 <div align="center"> 11 12 <h1>课程详细信息查询</h1> 13 <table border="1"> 14 <tr> 15 <td>课程名称</td> 16 <td>任课教师</td> 17 <td>课程编号</td> 18 <td>课程人数</td> 19 <td>选课人数</td> 20 </tr> 21 <tr> 22 <td>${param.name}</td> 23 <td>${param.teacher}</td> 24 <td>${param.pid}</td> 25 <td>${param.number}</td> 26 <td>${param.count}</td> 27 </tr> 28 </table> 29 </div> 30 31 </body> 32 </html>
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="utf-8"> 8 <title></title> 9 </head> 10 <body> 11 <div align="center"> 12 <h1>选课结果浏览:</h1> 13 14 <form action="TeacherServlet?method=searchclass" method="post" onsubmit="return check()"> 15 <table> 16 <tr> 17 <td>课程名称</td> 18 <td>已选课人数</td> 19 <td>课程总人数</td> 20 21 </tr> 22 <c:forEach items="${list}" var="item"> 23 <tr> 24 <td><a href="showclassinfo.jsp?name=${item.name}&teacher=${item.teacher}&pid=${item.pid}&number=${item.number}&count=${item.count}">${item.name}</a></td> 25 <td><a href="TeacherServlet?method=checkstudent&id=${item.pid}">${item.count}</a></td> 26 <td>${item.number}</td> 27 28 </tr> 29 </c:forEach> 30 </table> 31 </form> 32 </div> 33 34 </body> 35 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="UTF-8"> 8 <title></title> 9 </head> 10 <body> 11 <div align="center"> 12 <h1>学生信息浏览</h1> 13 <form action="TeacherServlet?method=checkstudent" method="post" > 14 <table border="1"> 15 <tr> 16 <td>学生姓名</td> 17 <td>学生专业</td> 18 </tr> 19 20 <c:forEach items="${list}" var="item"> 21 <tr> 22 <td><a href="showstudentinfos.jsp?id=${item.id}&name=${item.name}&sex=${item.sex}&classes=${item.classes}&zhuanye=${item.zhuanye}">${item.name}</a></td> 23 <td>${item.zhuanye}</td> 24 </tr> 25 </c:forEach> 26 27 </table> 28 </form> 29 </div> 30 31 </body> 32 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title></title> 8 </head> 9 <body> 10 <div align="center"> 11 12 <h1>学生详细信息</h1> 13 <table border="1"> 14 <tr> 15 <td>学生学号</td> 16 <td>学生姓名</td> 17 <td>学生性别</td> 18 <td>学生班级</td> 19 <td>学生专业</td> 20 </tr> 21 <tr> 22 <td>${param.id}</td> 23 <td>${param.name}</td> 24 <td>${param.sex}</td> 25 <td>${param.classes}</td> 26 <td>${param.zhuanye}</td> 27 </tr> 28 </table> 29 </div> 30 31 </body> 32 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="UTF-8"> 8 <title></title> 9 </head> 10 <body> 11 <div align="center"> 12 <h1>教师信息浏览</h1> 13 <form action="TeacherServlet?method=seacrch" method="post" > 14 <table border="1"> 15 <tr> 16 <td>教师工号</td> 17 <td>教师姓名</td> 18 <td>教师性别</td> 19 <td>所在院系</td> 20 <td>教师职称</td> 21 </tr> 22 23 <c:forEach items="${list}" var="item"> 24 <tr> 25 <td>${item.id}</td> 26 <td>${item.name}</td> 27 <td>${item.sex}</td> 28 <td>${item.xueyuan}</td> 29 <td>${item.zhicheng}</td> 30 </tr> 31 </c:forEach> 32 33 </table> 34 </form> 35 </div> 36 37 </body> 38 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>课程信息管理系统:学生界面</title> 8 9 <style type="text/css"> 10 11 .headframe{ 12 100%; 13 height:130px; 14 border:0; 15 } 16 17 .leftframe{ 18 float:left; 19 250px; 20 height:600px; 21 border:0; 22 } 23 24 .mainframe{ 25 float:right; 26 1200px; 27 height:600px; 28 border:0; 29 } 30 31 </style> 32 33 <script type="text/javascript"> 34 35 36 37 </script> 38 39 </head> 40 <body onload="onload()"> 41 </body> 42 43 <iframe src="head.jsp" class="headframe" scrolling="no"></iframe> 44 <iframe src="left1.jsp" class="leftframe" scrolling="no"></iframe> 45 <iframe src="main.jsp" name="mainAction" class="mainframe"></iframe> 46 47 48 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>课程信息管理系统:教师界面</title> 8 9 <style type="text/css"> 10 11 .headframe{ 12 100%; 13 height:130px; 14 border:0; 15 } 16 17 .leftframe{ 18 float:left; 19 250px; 20 height:600px; 21 border:0; 22 } 23 24 .mainframe{ 25 float:right; 26 1200px; 27 height:600px; 28 border:0; 29 } 30 31 </style> 32 33 </head> 34 35 36 <iframe src="head.jsp" class="headframe" scrolling="no"></iframe> 37 <iframe src="left2.jsp" class="leftframe" scrolling="no"></iframe> 38 <iframe src="main.jsp" name="mainAction" class="mainframe"></iframe> 39 40 41 </html>
1 <%@page import="com.Dao.*"%> 2 <%@page import="com.Bean.*"%> 3 <%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%> 4 <%@page import="java.util.ArrayList"%> 5 <%@page import="java.util.List" %> 6 <%@ page language="java" contentType="text/html; charset=UTF-8" 7 pageEncoding="UTF-8"%> 8 <!DOCTYPE html> 9 <html> 10 <head> 11 <meta charset="UTF-8"> 12 <title>修改学生信息</title> 13 14 <style type="text/css"> 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 </style> 31 32 </head> 33 <script type="text/javascript"> 34 function onload() 35 { 36 <% 37 Cookie[] cookies=request.getCookies(); 38 String value=""; 39 ArrayList<student> list=new ArrayList<>(); 40 if(cookies!=null){ 41 System.out.println("cookie的长度为:"+cookies.length); 42 for(int i=0;i<cookies.length;i++) 43 { 44 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 </script> 56 <body onload="onload()"> 57 58 <div class="container"> 59 <section> 60 <form action="StudentServlet?method=update" method="post" onsubmit="return check()"> 61 <%for(student s:list) 62 { 63 64 %> 65 66 <span class="cname" style="background-color: red">学号</span> 67 <input type="text" name="id" class="icname" placeholder=" class-name" id="id" readonly="readonly" value=<%=s.getId()%> > 68 <br/> 69 70 <span class="teacher">姓名</span> 71 <input type="text" name="name" class="iteacher" placeholder=" teacher" id="name" value=<%=s.getName()%> > 72 <br/> 73 74 <span class="place">性别</span> 75 <label><input type="radio" name="sex" id="sex" value="男">男</label> 76 <label><input type="radio" name="sex" id="sex" value="女">女</label> 77 <br/> 78 79 80 81 <span class="place">班级</span> 82 <input type="text" name="classes" class="iteacher" placeholder=" classes" id="classes" value=<%=s.getClasses() %>> 83 <br/> 84 85 86 <span class="place">专业</span> 87 <input type="text" name="zhuanye" class="iteacher" placeholder=" zhuangye" id="zhuanye" value=<%=s.getZhuanye() %>> 88 <br/> 89 <% } %> 90 <input type="submit" value="保存" class="butn"> 91 <br/> 92 </form> 93 </section> 94 </div> 95 96 <script type="text/javascript"> 97 98 99 </script> 100 101 </body> 102 </html>
1 <%@page import="com.Dao.*"%> 2 <%@page import="com.Bean.*"%> 3 <%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%> 4 <%@page import="java.util.ArrayList"%> 5 <%@page import="java.util.List" %> 6 <%@ page language="java" contentType="text/html; charset=UTF-8" 7 pageEncoding="UTF-8"%> 8 <!DOCTYPE html> 9 <html> 10 <head> 11 <meta charset="UTF-8"> 12 <title>修改教师信息</title> 13 14 <style type="text/css"> 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 </style> 31 <script type="text/javascript"> 32 function onload() 33 { 34 <% 35 Cookie[] cookies=request.getCookies(); 36 String value=""; 37 ArrayList<teacher> list=new ArrayList<>(); 38 if(cookies!=null){ 39 System.out.println("cookie的长度为:"+cookies.length); 40 for(int i=0;i<cookies.length;i++) 41 { 42 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 </script> 54 55 </head> 56 <body> 57 58 <div class="container"> 59 <section> 60 <form action="TeacherServlet?method=update" method="post" onsubmit="return check()"> 61 <%for(teacher s:list) 62 { 63 64 %> 65 <span class="cname">工号</span> 66 <input type="text" name="id" class="icname" placeholder=" class-name" id="id" readonly="readonly" value=<%=s.getId()%>> 67 <br/> 68 69 <span class="teacher">姓名</span> 70 <input type="text" name="name" class="iteacher" placeholder=" teacher" id="name" value=<%=s.getName()%>> 71 <br/> 72 73 <span class="place">性别</span> 74 <label><input type="radio" name="sex" id="sex" value="男">男</label> 75 <label><input type="radio" name="sex" id="sex" value="女">女</label> 76 <br/> 77 78 <span class="place">学院</span> 79 <input type="text" name="xueyuan" class="iteacher" placeholder=" teacher" id="xueyuan" value=<%=s.getXueyuan()%>> 80 <br/> 81 82 83 <span class="place">职称</span> 84 <input type="text" name="zhicheng" class="iteacher" placeholder=" teacher" id="zhicheng" value=<%=s.getZhicheng()%>> 85 <br/> 86 <% } %> 87 <input type="submit" value="保存" class="butn"> 88 <br/> 89 </form> 90 </section> 91 </div> 92 93 <script type="text/javascript"> 94 95 96 </script> 97 98 </body> 99 </html>
登陆界面:
操作界面:
学生:
老师:
管理员: