选课系统
石家庄铁道大学选课管理系统
1、项目需求:
本项目所开发的学生选课系统完成学校对学生的选课信息的统计与管理,减少数据漏掉的情况,同时也节约人力、物力和财力。告别以往的人工统计。
2.系统要求与功能设计
2.1 页面要求
(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;
(2)网站页面整体风格统一;
(3)首页(登录页)要求实现不同用户登录后,进入的功能页不相同。
(4)教师功能页:有添加课程、修改个人信息、浏览选课学生信息三个模块。
(5)学生功能页:有修改个人信息、浏览课程信息、选课三个功能模块。
(5)管理员功能页:有添加教师信息、添加学生信息两个模块。
2.2功能要求:
(1)添加教师信息:管理员可以添加教师基本信息,教师基本信息包括:教师工号(八位数字组成,例如02000081)、教师姓名、教师性别、教师所在学院、职称(教授、副教授、讲师、助教)组成;
(2)添加学生信息:管理可以添加学生基本信息,学生基本信息包括学号(八位数字组成,例如20180052)、学生姓名、学生性别、所在班级、所属专业组成;
(3)添加课程信息:教师登陆后,可以添加自己任职的课程基本信息,课程基本信息包括:课程编号(六位数字组成,例如050013),课程名称、选课人数、任课教师(任课教师不需录入,那位教师填写课程信息,那位教师就是任课教师);
(4)修改个人信息:教师或学生登陆后可以修改个人信息,但教师工号或学号不能修改,另外教师或学生只能修改自己的信息,无法看到或修改其他学生或教师的基本信息。
(5)浏览课程信息:学生登陆后可以看到所有课程的列表信息,点击课程名称可以查看课程的详细信息,包括已选课人数;点击教师名称可以查看教师的详细信息。
(6)选课:进入选课页面,课程信息列表显示所有选课人数未达到课程设置的选课人数上限,点击课程名称可以看到课程详细信息,点击课程详细信息页面的“选课”按钮,可以实现选课功能。
(7)浏览选课学生信息:教师进入该页面后,可以看到自己设置的课程信息列表,点击课程名称,可以看到,选择该课程的所有学生基本信息列表。
(8)登陆功能:管理员、教师、学生登陆后可以看到不同的功能页面,教师或学生登陆后只能看到自己的相关信息,不同教师、不同学生登陆后无法查看其他人的信息。(要求至少创建两个教师用户、十个学生用户演示选课过程)
3数据库设计:
要求实现课程基本信息表、教师基本信息表、学生基本信息表、选课基本信息表。(提示:选课基本信息包括课程编号、教师编号、学号等基本信息)
4、WEB发布:
要求可以实现在浏览器直接访问系统。
代码:
Dao
package Dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import DBUtil.DBUtil; import Javabean.Cou; import Javabean.Jibenxinxi; import Javabean.Stu; import Javabean.Teacher; public class Dao { public int searchPid(String username,String password) { Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; int pid=0; try { String sql="select pid from user where username= '"+username+"' and password='"+password+"'"; state = conn.createStatement(); rs = state.executeQuery(sql); while(rs.next()){ pid = rs.getInt("pid"); } } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } return pid; } public boolean addtea(Teacher teacher) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into teacher(tpid,teaname,sex,txueyuan,zhicheng) value(?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, teacher.getTpid()); pstmt.setString(2, teacher.getTeaname()); pstmt.setString(3, teacher.getSex()); pstmt.setString(4, teacher.getTxueyuan()); pstmt.setString(5, teacher.getZhicheng()); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public boolean adduser(String tpid,String password,int pid) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into user(username,password,pid) value(?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, tpid); pstmt.setString(2, password); pstmt.setInt(3, pid); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public boolean addstu(Stu stu) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into stu(spid,stuname,sex,banji,ye) value(?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, stu.getSpid()); pstmt.setString(2, stu.getStuname()); pstmt.setString(3, stu.getSex()); pstmt.setString(4, stu.getBanji()); pstmt.setString(5, stu.getYe()); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public String searchteaname(String tpid) { Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; String teaname=null; try { String sql="select teaname from teacher where tpid= '"+tpid+"'"; state = conn.createStatement(); rs = state.executeQuery(sql); while(rs.next()){ teaname = rs.getString("teaname"); } } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } return teaname; } public boolean addcou(Cou cou) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into cou(cpid,cname,num,snum,jiaoshi) value(?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, cou.getCpid()); pstmt.setString(2, cou.getCname()); pstmt.setInt(3, cou.getNum()); pstmt.setInt(4, cou.getSnum()); pstmt.setString(5, cou.getJiaoshi()); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public boolean updatetea(Teacher teacher) { String sql = "update teacher set teaname='" + teacher.getTeaname() + "', sex='" + teacher.getSex() + "', txueyuan='" +teacher.getTxueyuan() + "',zhicheng='" +teacher.getZhicheng() + "'where tpid='" + teacher.getTpid() + "'"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); System.out.println("看看是不是执行了"); a = state.executeUpdate(sql); System.out.println(a); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } System.out.println(f); return f; } public boolean updatestu(Stu stu) { String sql = "update stu set stuname='" + stu.getStuname() + "', sex='" + stu.getSex() + "', banji='" +stu.getBanji() + "',ye='" +stu.getYe() + "'where spid='" + stu.getSpid() + "'"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); System.out.println("看看是不是执行了"); a = state.executeUpdate(sql); System.out.println(a); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } System.out.println(f); return f; } public List<Cou> liulankecheng() { String sql = "select * from cou"; List<Cou> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Cou bean = null; while (rs.next()) { int id = rs.getInt("id"); String cpid = rs.getString("cpid"); String cname = rs.getString("cname"); int num = rs.getInt("num"); int snum = rs.getInt("snum"); String jiaoshi = rs.getString("jiaoshi"); bean = new Cou(id,cpid, cname, num ,snum,jiaoshi); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } public Cou searchByid(int id) { String sql = "select * from cou where id= '"+id+"'"; Cou cou = null; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { //int id = rs.getInt("id"); String cpid = rs.getString("cpid"); String cname = rs.getString("cname"); int num = rs.getInt("num"); int snum = rs.getInt("snum"); String jiaoshi = rs.getString("jiaoshi"); cou = new Cou(cpid, cname, num ,snum,jiaoshi); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return cou; } public boolean updatecou(int id,int snum) { String sql="update cou set snum='" + snum + "'where id='" + id +"'"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); System.out.println("看看是不是执行了"); a = state.executeUpdate(sql); System.out.println(a); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } System.out.println(f); return f; } public String searchtpid(String jiaoshi) { String sql = "select tpid from teacher where teaname= '"+jiaoshi+"'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; String tpid=null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { tpid=rs.getString("tpid"); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return tpid; } public Stu searchstu(String spid) { String sql = "select * from stu where spid= '"+spid+"'"; Stu stu = null; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { //int id = rs.getInt("id"); String spid1 = rs.getString("spid"); String stuname = rs.getString("stuname"); String sex = rs.getString("sex"); String banji = rs.getString("banji"); String ye = rs.getString("ye"); stu = new Stu(spid1, stuname, sex ,banji,ye); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return stu; } public boolean addjiben(String cpid,String tpid,String spid,Stu stu) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a=0; try { String sql = "insert into jiben(cpid,tpid,spid,stuname,sex,banji,ye) value(?,?,?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, cpid); pstmt.setString(2, tpid); pstmt.setString(3, spid); pstmt.setString(4, stu.getStuname()); pstmt.setString(5, stu.getSex()); pstmt.setString(6, stu.getBanji()); pstmt.setString(7, stu.getYe()); a = pstmt.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if(a>0) f=true; return f; } public List<Cou> liulankecheng1() { String sql = "select * from cou"; List<Cou> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Cou bean = null; while (rs.next()) { int id = rs.getInt("id"); String cpid = rs.getString("cpid"); String cname = rs.getString("cname"); int num = rs.getInt("num"); int snum = rs.getInt("snum"); String jiaoshi = rs.getString("jiaoshi"); if(snum<num) { bean = new Cou(id,cpid, cname, num ,snum,jiaoshi); list.add(bean); } } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } public List<Jibenxinxi> searchstuinfo(String tpid) { String sql = "select * from jiben where tpid= '"+tpid+"'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; List<Jibenxinxi> list = new ArrayList<>(); try { state = conn.createStatement(); rs = state.executeQuery(sql); Jibenxinxi jiben = null; while (rs.next()) { //int id = rs.getInt("id"); String cpid = rs.getString("cpid"); String tpid1 = rs.getString("tpid"); String spid = rs.getString("spid"); String stuname = rs.getString("stuname"); String sex = rs.getString("sex"); String banji = rs.getString("banji"); String ye = rs.getString("ye"); jiben = new Jibenxinxi(cpid,tpid1,spid,stuname,sex ,banji,ye); list.add(jiben); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } }
Dubtil
package DBUtil; import java.sql.*; /** * 数据库连接工具 * @author Hu * */ public class DBUtil { public static String url = "jdbc:mysql://localhost:3306/xuanke?serverTimezone=UTC"; public static String user = "root"; public static String password = "123456"; public static Connection getConn () { Connection conn = null; try { Class.forName("com.mysql.cj.jdbc.Driver");//加载驱动 conn = DriverManager.getConnection(url, user, password); } catch (Exception e) { e.printStackTrace(); } return conn; } /** * 关闭连接 * @param state * @param conn */ public static void close (PreparedStatement preparedState, Connection conn) { if (preparedState != null) { try { preparedState.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, PreparedStatement preparedState, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (preparedState != null) { try { preparedState.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } /** * 关闭连接 * @param state * @param conn */ public static void close (Statement state, Connection conn) { if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, Statement state, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void main(String[] args) throws SQLException { Connection conn = getConn(); PreparedStatement preparedStatement = null; ResultSet rs = null; String sql ="select * from xuanke"; preparedStatement = conn.prepareStatement(sql); rs = preparedStatement.executeQuery(); if(rs.next()){ System.out.println("数据库为空"); } else{ System.out.println("数据库不为空"); } } }
Javabean
package Javabean; public class Cou { private int id; private String cpid; private String cname; private int num; private int snum; private String jiaoshi; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getCpid() { return cpid; } public void setCpid(String cpid) { this.cpid = cpid; } public String getCname() { return cname; } public void setCname(String cname) { this.cname = cname; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } public int getSnum() { return snum; } public void setSnum(int snum) { this.snum = snum; } public String getJiaoshi() { return jiaoshi; } public void setJiaoshi(String jiaoshi) { this.jiaoshi = jiaoshi; } public Cou() {} public Cou(int id,String cpid,String cname,int num,int snum,String jiaoshi) { this.id=id; this.cpid=cpid; this.cname=cname; this.num=num; this.snum=snum; this.jiaoshi=jiaoshi; } public Cou(String cpid,String cname,int num,int snum,String jiaoshi) { this.cpid=cpid; this.cname=cname; this.num=num; this.snum=snum; this.jiaoshi=jiaoshi; } }
package Javabean; public class Jibenxinxi { private int id; private String cpid; private String tpid; private String spid; private String stuname; private String sex; private String banji; private String ye; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getCpid() { return cpid; } public void setCpid(String cpid) { this.cpid = cpid; } public String getTpid() { return tpid; } public void setTpid(String tpid) { this.tpid = tpid; } public String getSpid() { return spid; } public void setSpid(String spid) { this.spid = spid; } public String getStuname() { return stuname; } public void setStuname(String stuname) { this.stuname = stuname; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getBanji() { return banji; } public void setBanji(String banji) { this.banji = banji; } public String getYe() { return ye; } public void setYe(String ye) { this.ye = ye; } public Jibenxinxi() { } public Jibenxinxi(int id,String cpid,String tpid,String spid,String stuname,String sex,String banji,String ye) { this.id=id; this.cpid=cpid; this.tpid=tpid; this.spid=spid; this.stuname=stuname; this.sex=sex; this.banji=banji; this.ye=ye; } public Jibenxinxi(String cpid,String tpid,String spid,String stuname,String sex,String banji,String ye) { this.cpid=cpid; this.tpid=tpid; this.spid=spid; this.stuname=stuname; this.sex=sex; this.banji=banji; this.ye=ye; } }
package Javabean; public class Stu { private int id; private String spid; private String stuname; private String sex; private String banji; private String ye; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getSpid() { return spid; } public void setSpid(String spid) { this.spid = spid; } public String getStuname() { return stuname; } public void setStuname(String stuname) { this.stuname = stuname; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getBanji() { return banji; } public void setBanji(String banji) { this.banji = banji; } public String getYe() { return ye; } public void setYe(String ye) { this.ye = ye; } public Stu() { } public Stu(int id,String spid,String stuname,String sex,String banji,String ye) { this.id=id; this.spid=spid; this.stuname=stuname; this.sex=sex; this.banji=banji; this.ye=ye; } public Stu(String spid,String stuname,String sex,String banji,String ye) { this.spid=spid; this.stuname=stuname; this.sex=sex; this.banji=banji; this.ye=ye; } }
package Javabean; public class Teacher { private int id; private String tpid; private String teaname; private String sex; private String txueyuan; private String zhicheng; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTpid() { return tpid; } public void setTpid(String tpid) { this.tpid = tpid; } public String getTeaname() { return teaname; } public void setTeaname(String teaname) { this.teaname = teaname; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getTxueyuan() { return txueyuan; } public void setTxueyuan(String txueyuan) { this.txueyuan = txueyuan; } public String getZhicheng() { return zhicheng; } public void setZhicheng(String zhicheng) { this.zhicheng = zhicheng; } public Teacher() { } public Teacher(int id,String tpid,String teaname,String sex,String txueyuan,String zhicheng) { this.id=id; this.tpid=tpid; this.teaname=teaname; this.sex=sex; this.txueyuan=txueyuan; this.zhicheng=zhicheng; } public Teacher(String tpid,String teaname,String sex,String txueyuan,String zhicheng) { this.tpid=tpid; this.teaname=teaname; this.sex=sex; this.txueyuan=txueyuan; this.zhicheng=zhicheng; } }
xuekeSevelet
package xuankeServlet; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Dao.Dao; import Javabean.Cou; import Javabean.Jibenxinxi; import Javabean.Stu; import Javabean.Teacher; @WebServlet("/xuankeServlet") public class xuankeServlet extends HttpServlet{ /** * 特有id号 */ private static final long serialVersionUID = 1L; Dao dao = new Dao(); /** * 方法选择 * @return * @throws IOException * @throws ServletException */ protected void service(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String method = req.getParameter("method"); if("login".equals(method)) { login(req,resp); }else if("addtea".equals(method)) { addtea(req,resp); }else if("addstu".equals(method)) { addstu(req,resp); }else if("addcou".equals(method)) { addcou(req,resp); }else if("updatetea".equals(method)) { updatetea(req,resp); }else if("updatestu".equals(method)) { updatestu(req,resp); }else if("liulankecheng".equals(method)) { liulankecheng(req,resp); }else if("chakan".equals(method)) { chakan(req,resp); }else if("xuanke".equals(method)) { xuanke(req,resp); }else if("liulankecheng1".equals(method)) { liulankecheng1(req,resp); }else if("liulanstu".equals(method)) { liulanstu(req,resp); } } private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub req.setCharacterEncoding("utf-8"); String username = req.getParameter("username"); String password=req.getParameter("password"); int pid=dao.searchPid(username,password); System.out.println(pid); if(pid==1) { String teaname=dao.searchteaname(username); System.out.println(teaname); req.getSession().setAttribute("username", username); req.getSession().setAttribute("teaname", teaname); } if(pid==2) { req.getSession().setAttribute("username1", username); } req.setAttribute("pid", pid); req.getRequestDispatcher("houtai.jsp").forward(req, resp); } private void addtea(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String tpid = req.getParameter("tpid"); String teaname = req.getParameter("teaname"); String sex = req.getParameter("sex"); String txueyuan = req.getParameter("txueyuan"); String zhicheng = req.getParameter("zhicheng"); int pid=1; String password = "123456"; Teacher teacher=new Teacher(tpid,teaname,sex,txueyuan,zhicheng); if(dao.addtea(teacher)&&dao.adduser(tpid,password,pid)) { req.setAttribute("teacher",teacher); req.setAttribute("message","添加成功" ); req.getRequestDispatcher("addtea.jsp").forward(req, resp); }else { req.setAttribute("message","老师姓名重复,请重新输入" ); req.getRequestDispatcher("addtea.jsp").forward(req, resp); } } private void addstu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String spid = req.getParameter("spid"); String stuname = req.getParameter("stuname"); String sex = req.getParameter("sex"); String banji = req.getParameter("banji"); String ye = req.getParameter("ye"); Stu stu=new Stu(spid,stuname,sex,banji,ye); int pid=2; String password="123456"; if(dao.addstu(stu)&&dao.adduser(spid, password, pid)) { req.setAttribute("stu",stu); req.setAttribute("message","添加成功" ); req.getRequestDispatcher("addstu.jsp").forward(req, resp); }else { req.setAttribute("message","学生姓名重复,请重新输入" ); req.getRequestDispatcher("addstu.jsp").forward(req, resp); } } private void addcou(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String jiaoshi=(String) req.getSession().getAttribute("teaname"); String cpid = req.getParameter("cpid"); String cname = req.getParameter("cname"); int num = Integer.parseInt(req.getParameter("num")); int snum=0; System.out.println(jiaoshi); Cou cou=new Cou(cpid,cname,num,snum,jiaoshi); if(dao.addcou(cou)) { req.setAttribute("cou",cou); req.setAttribute("message","添加成功" ); req.getRequestDispatcher("addcourse.jsp").forward(req, resp); }else { req.setAttribute("message","课程信息重复,请重新输入" ); req.getRequestDispatcher("addcourse.jsp").forward(req, resp); } } private void updatetea(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String tpid=(String) req.getSession().getAttribute("username"); String teaname = req.getParameter("teaname"); String sex = req.getParameter("sex"); String txueyuan = req.getParameter("txueyuan"); String zhicheng = req.getParameter("zhicheng"); Teacher teacher=new Teacher(tpid,teaname,sex,txueyuan,zhicheng); if(dao.updatetea(teacher)) { req.setAttribute("message","修改成功" ); req.getRequestDispatcher("updatet.jsp").forward(req, resp); } else { req.setAttribute("message","修改失败" ); req.getRequestDispatcher("updatet.jsp").forward(req, resp); } } private void updatestu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String spid =(String) req.getSession().getAttribute("username1"); String stuname = req.getParameter("stuname"); String sex = req.getParameter("sex"); String banji = req.getParameter("banji"); String ye = req.getParameter("ye"); Stu stu=new Stu(spid,stuname,sex,banji,ye); if(dao.updatestu(stu)) { req.setAttribute("message","修改成功" ); req.getRequestDispatcher("updates.jsp").forward(req, resp); } else { req.setAttribute("message","修改失败" ); req.getRequestDispatcher("updates.jsp").forward(req, resp); } } private void liulankecheng(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); List<Cou> cous = dao.liulankecheng(); req.setAttribute("cous", cous); req.getRequestDispatcher("liulankecheng.jsp").forward(req, resp); } private void chakan(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); int id = Integer.parseInt(req.getParameter("id")); Cou cou=dao.searchByid(id); req.getSession().setAttribute("id", id); req.setAttribute("cou", cou); req.getRequestDispatcher("chakankecheng.jsp").forward(req, resp); } private void xuanke(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String spid =(String) req.getSession().getAttribute("username1"); String cpid = req.getParameter("cpid"); int snum = Integer.parseInt(req.getParameter("snum"))+1; String jiaoshi = req.getParameter("jiaoshi"); int id =(int) req.getSession().getAttribute("id"); String tpid=dao.searchtpid(jiaoshi); Stu stu = dao.searchstu(spid); System.out.println(id); if(dao.updatecou(id,snum)&&dao.addjiben(cpid,tpid,spid,stu)) { req.setAttribute("message","选课成功" ); req.getRequestDispatcher("sucess.jsp").forward(req, resp); } else { req.setAttribute("message","选课失败" ); req.getRequestDispatcher("sucess.jsp").forward(req, resp); } } private void liulankecheng1(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); List<Cou> cous = dao.liulankecheng1(); req.setAttribute("cous", cous); req.getRequestDispatcher("liulankecheng1.jsp").forward(req, resp); } private void liulanstu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String tpid=(String) req.getSession().getAttribute("username"); List<Jibenxinxi> jibens = dao.searchstuinfo(tpid); req.setAttribute("jibens",jibens); req.getRequestDispatcher("liulanstu.jsp").forward(req, resp); } }