• 选课系统JAVAWEB后台


    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;
        }
    }
    package DBUtil;
     
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
     
    public class DBUtil {
         
        public static String db_url = "jdbc:mysql://localhost:3306/xuanke?useSSL=false";
        public static String db_user = "root";
        public static String db_pass = "root";
         
        public static Connection getConn () {
            Connection conn = null;
             
            try {
                Class.forName("com.mysql.jdbc.Driver");//鍔犺浇椹卞姩
                conn = DriverManager.getConnection(db_url, db_user, db_pass);
            } catch (Exception e) {
                e.printStackTrace();
            }
             
            return conn;
        }
         
        /*10鍏抽棴杩炴帴*/
        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 pstmt = null;
            ResultSet rs = null;
            String sql ="select * from user";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            if(rs.next()){
                System.out.println("123");
            }else{
                System.out.println("456");
            }
        }
    }
    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;
        }
    }
    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);
        }
        
    }
  • 相关阅读:
    JCTF 2014(Reverse)
    JCTF 2014(Misc)
    实验吧CTF题库-密码学(部分)
    第四章 Jinja2模版
    第三章 URL与视图
    flask学习导航主页
    flask调试模式
    rontab踩坑(三):crontab定时任务调度机制与系统时间/时区的不一致
    crontab踩坑(二):Unit crond.service could not be found.
    crontab踩坑(一)
  • 原文地址:https://www.cnblogs.com/520520520zl/p/12151697.html
Copyright © 2020-2023  润新知