选课管理系统

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发布:

要求可以实现在浏览器直接访问系统。

代码如下

  1 package Bean;
  2 
  3 public class ChooseClass {
  4     String snumber;
  5     String cnumber;
  6     String sname;
  7     String cname;
  8     String cteacher;
  9     String most;
 10     String have;
 11     public ChooseClass() {
 12         
 13     }
 14     
 15     public ChooseClass(String snumber,String sname,String cnumber,String cname,String cteacher,String most,String have) {
 16         this.cname=cname;
 17         this.sname=sname;
 18         this.snumber=snumber;
 19         this.cnumber=cnumber;
 20         this.cteacher=cteacher;
 21         this.most=most;
 22         this.have=have;
 23     }
 24 
 25     public String getSname() {
 26         return sname;
 27     }
 28 
 29     public void setSname(String sname) {
 30         this.sname = sname;
 31     }
 32 
 33     public String getSnumber() {
 34         return snumber;
 35     }
 36 
 37     public void setSnumber(String snumber) {
 38         this.snumber = snumber;
 39     }
 40 
 41     public String getCnumber() {
 42         return cnumber;
 43     }
 44 
 45     public void setCnumber(String cnumber) {
 46         this.cnumber = cnumber;
 47     }
 48 
 49     public String getCname() {
 50         return cname;
 51     }
 52 
 53     public void setCname(String cname) {
 54         this.cname = cname;
 55     }
 56 
 57     public String getCteacher() {
 58         return cteacher;
 59     }
 60 
 61     public void setCteacher(String cteacher) {
 62         this.cteacher = cteacher;
 63     }
 64 
 65     public String getMost() {
 66         return most;
 67     }
 68 
 69     public void setMost(String most) {
 70         this.most = most;
 71     }
 72 
 73     public String getHave() {
 74         return have;
 75     }
 76 
 77     public void setHave(String have) {
 78         this.have = have;
 79     }
 80     
 81 }
 82 
 83 
 84 
 85 
 86 
 87 package Bean;
 88 
 89 public class Classes {
 90     String cnumber;
 91     String cname;
 92     String cteacher;
 93     int most;
 94     int have;
 95     
 96     public Classes(String cnumber,String cname,String cteacher,int most) {
 97         this.cnumber=cnumber;
 98         this.cname=cname;
 99         this.cteacher=cteacher;
100         this.most=most;
101         this.have=0;
102     }
103     public Classes(String cnumber,String cname,String cteacher,int most,int have) {
104         this.cnumber=cnumber;
105         this.cname=cname;
106         this.cteacher=cteacher;
107         this.most=most;
108         this.have=have;
109     }
110 
111     public String getCnumber() {
112         return cnumber;
113     }
114 
115     public void setCnumber(String cnumber) {
116         this.cnumber = cnumber;
117     }
118 
119     public String getCname() {
120         return cname;
121     }
122 
123     public void setCname(String cname) {
124         this.cname = cname;
125     }
126 
127     public String getCteacher() {
128         return cteacher;
129     }
130 
131     public void setCteacher(String cteacher) {
132         this.cteacher = cteacher;
133     }
134 
135     public int getMost() {
136         return most;
137     }
138 
139     public void setMost(int most) {
140         this.most = most;
141     }
142 
143     public int getHave() {
144         return have;
145     }
146 
147     public void setHave(int have) {
148         this.have = have;
149     }
150     
151     
152     
153 }
154 
155 
156 package Bean;
157 
158 public class Login {
159     String account;
160     String password;
161     public Login(String account,String password) {
162         this.account=account;
163         this.password=password;
164     }
165     public String getAccount() {
166         return account;
167     }
168     public void setAccount(String account) {
169         this.account = account;
170     }
171     public String getPassword() {
172         return password;
173     }
174     public void setPassword(String password) {
175         this.password = password;
176     }
177 }
178 
179 
180 package Bean;
181 
182 public class Student {
183     String sname;
184     String snumber;
185     String ssex;
186     String sgrade;            //班级
187     String specialities;    //专业
188     String password;
189     public Student(String sname,String snumber,String ssex,String sgrade,String specialities) {
190         this.sname=sname;
191         this.snumber=snumber;
192         this.password=snumber;
193         this.ssex=ssex;
194         this.sgrade=sgrade;
195         this.specialities=specialities;
196         
197     }
198     public Student(String sname,String snumber,String password,String ssex,String sgrade,String specialities) {
199         this.sname=sname;
200         this.snumber=snumber;
201         this.password=password;
202         this.ssex=ssex;
203         this.sgrade=sgrade;
204         this.specialities=specialities;
205         
206     }
207     public String getPassword() {
208         return password;
209     }
210 
211     public void setPassword(String password) {
212         this.password = password;
213     }
214 
215     public String getSname() {
216         return sname;
217     }
218 
219     public void setSname(String sname) {
220         this.sname = sname;
221     }
222 
223     public String getSnumber() {
224         return snumber;
225     }
226 
227     public void setSnumber(String snumber) {
228         this.snumber = snumber;
229     }
230 
231     public String getSsex() {
232         return ssex;
233     }
234 
235     public void setSsex(String ssex) {
236         this.ssex = ssex;
237     }
238 
239     public String getSgrade() {
240         return sgrade;
241     }
242 
243     public void setSgrade(String sgrade) {
244         this.sgrade = sgrade;
245     }
246 
247     public String getSpecialities() {
248         return specialities;
249     }
250 
251     public void setSpecialities(String specialities) {
252         this.specialities = specialities;
253     }
254 
255 
256 }
257 
258 
259 package Bean;
260 
261 public class Teacher {
262     String tname;
263     String tnumber;
264     String tsex;
265     String tacademy;
266     String twork;        //职称
267     String password;
268     public Teacher(String tname,String tnumber,String tsex,String tacademy,String twork) {
269         this.tname=tname;
270         this.tacademy=tacademy;
271         this.tnumber=tnumber;
272         this.tsex=tsex;
273         this.twork=twork;
274         this.password=tnumber;
275     }
276     
277     public String getTname() {
278         return tname;
279     }
280     public void setTname(String tname) {
281         this.tname = tname;
282     }
283     public String getTnumber() {
284         return tnumber;
285     }
286     public void setTnumber(String tnumber) {
287         this.tnumber = tnumber;
288     }
289     public String getTsex() {
290         return tsex;
291     }
292     public void setTsex(String tsex) {
293         this.tsex = tsex;
294     }
295     public String getTacademy() {
296         return tacademy;
297     }
298     public void setTacademy(String tacademy) {
299         this.tacademy = tacademy;
300     }
301     public String getTwork() {
302         return twork;
303     }
304     public void setTwork(String twork) {
305         this.twork = twork;
306     }
307 
308     public String getPassword() {
309         return password;
310     }
311 
312     public void setPassword(String password) {
313         this.password = password;
314     }
315     
316     
317 }
Bean
  1 package 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 Bean.ChooseClass;
 11 import Bean.Classes;
 12 import DBUtil.DBUtil;
 13 
 14 public class ChooseDao {
 15     
 16     public boolean insert(String snumber,String sname, Classes cl)
 17     {
 18         
 19         String sql="insert into choose (snumber,sname,cnumber,cname,cteacher,most,have) values('"+snumber+"','"+sname+"','"+cl.getCnumber()+"','"+cl.getCname()+"','"+cl.getCteacher()+"','"+cl.getMost()+"','"+cl.getHave()+"')";
 20         Connection conn=DBUtil.getConn();//数据库连接,加载驱动
 21         boolean flag=false;
 22         if(!id(snumber,cl.getCnumber())) {
 23             Statement state=null;//数据库操作
 24             try
 25             {
 26                 state=conn.createStatement();//实例化Statement对象,方便对sql语句进行操作
 27                 state.executeUpdate(sql);
 28             }catch(Exception e)//当try语句中出现异常时,会执行catch中的语句
 29               {
 30                 e.printStackTrace();//捕获异常的语句
 31               }
 32              finally //finally作为异常处理的一部分,它只能用在try/catch语句中,并且附带一个语句块,表示这段语句最终一定会被执行(不管有没有抛出异常),经常被用在需要释放资源的情况下。
 33              {
 34                  DBUtil.close(state, conn); //close释放资源
 35              }
 36             ClassesDao cD=new ClassesDao();
 37             cD.chose(cl.getCnumber());
 38             flag=true;
 39         }
 40         
 41         return flag;
 42     }
 43     public boolean delete(String snumber,String cnumber)
 44     {
 45         String sql="delete from choose where snumber='"+snumber+"' and cnumber='"+cnumber+"'"  ;
 46         //删除语句:
 47         //delete from table_name where some_colume=some_value
 48         
 49         Connection conn=DBUtil.getConn();
 50         Statement state=null;
 51         
 52         try
 53         {
 54             state=conn.createStatement();
 55             state.executeUpdate(sql);
 56         }catch (Exception e)
 57         {
 58             e.printStackTrace();
 59         }
 60         finally
 61         {
 62             DBUtil.close(state, conn);
 63         }
 64         return false;
 65     }
 66     public boolean delete(String cnumber)
 67     {
 68         String sql="delete from choose where cnumber='"+cnumber+"'"  ;
 69         //删除语句:
 70         //delete from table_name where some_colume=some_value
 71         
 72         Connection conn=DBUtil.getConn();
 73         Statement state=null;
 74         
 75         try
 76         {
 77             state=conn.createStatement();
 78             state.executeUpdate(sql);
 79         }catch (Exception e)
 80         {
 81             e.printStackTrace();
 82         }
 83         finally
 84         {
 85             DBUtil.close(state, conn);
 86         }
 87         return false;
 88     }
 89     public boolean id(String snumber,String cnumber) {
 90         
 91         boolean flag = false;
 92         
 93         String sql = "select * from choose where snumber='"+snumber+"' and cnumber='"+cnumber+"' ";
 94         Connection conn = DBUtil.getConn();
 95         Statement state = null;
 96         ResultSet rs = null;
 97         
 98         try {
 99             state = conn.createStatement();
100             rs = state.executeQuery(sql);
101             //要用statement类的executeQuery()方法来下达select指令以查询数据库,
102             //executeQuery()方法会把数据库响应的查询结果存放在ResultSet类对象中供我们使用。
103             while (rs.next()) {
104                 flag = true;
105             }
106         }
107         catch (SQLException e) {
108             e.printStackTrace();
109         } finally {
110             DBUtil.close(rs, state, conn);
111         }
112         return flag;
113     }
114     public List<ChooseClass> list(String cnumber){
115         //插入sql语句
116         String sql="select * from choose where cnumber = '"+cnumber+"' order by id asc";
117         System.out.println(sql);
118         List<ChooseClass>list=new ArrayList<>();
119         //给集合list创造(new)一个存储空间用于存放数据
120         
121         
122         Connection conn=DBUtil.getConn();
123         Statement state=null;
124         ResultSet rs=null;
125         
126         try{
127             state=conn.createStatement();
128             rs=state.executeQuery(sql);
129             while(rs.next()) {//注意:这里用双引号,ID是表user里的ID列
130                 String snumber=rs.getString("snumber");
131                 String sname=rs.getString("sname");
132                 String cname=rs.getString("cname");
133                 String cteacher=rs.getString("cteacher");
134                 String most=rs.getString("most");
135                 String have=rs.getString("have");
136                 ChooseClass classes=new ChooseClass(snumber,sname, cnumber, cname, cteacher, most, have);
137                 list.add(classes);
138                 //表示,把bean里的数据存入到list当中
139             }
140         }
141         catch (SQLException e)
142         {
143             e.printStackTrace();
144         }
145         finally
146         {
147             DBUtil.close(state, conn);
148         }
149         return list;
150     }
151 }
152 
153 package Dao;
154 
155 import java.sql.Connection;
156 import java.sql.ResultSet;
157 import java.sql.SQLException;
158 import java.sql.Statement;
159 import java.util.ArrayList;
160 import java.util.List;
161 
162 import Bean.Classes;
163 import DBUtil.DBUtil;
164 
165 public class ClassesDao {
166     public boolean insert(Classes classes){
167         
168         String sql="insert into classes(cnumber,cname,cteacher,most,have) values('"+classes.getCnumber()+"','"+classes.getCname()+"','"+classes.getCteacher()+"','"+classes.getMost()+"','"+classes.getHave()+"')";
169         boolean flag=false;
170         if(!only(classes.getCnumber())) {
171             Connection conn=DBUtil.getConn();//添加数据库,加载驱动
172             Statement state=null;//创建statement对象并置空
173             try {
174                 state=conn.createStatement();
175                 state.executeUpdate(sql);
176             } catch (SQLException e) {
177                 e.printStackTrace();
178             }
179             finally {
180                 DBUtil.close(state, conn);//clase 释放资源
181             }
182             flag=true;
183         }
184         
185         
186         return flag;
187     }
188     
189     public boolean delete(String cnumber,String cname){
190         //插入sql 语句
191         String sql="delete from classes where cnumber='"+cnumber+"' and cname='"+cname+"'  ";
192         
193         //删除语句:
194         //delete from table_name where some_colume=some_value
195         
196         Connection conn =DBUtil.getConn();
197         Statement state=null;
198         try {
199             state=conn.createStatement();
200             state.executeUpdate(sql);
201         } catch (SQLException e) {
202             // TODO Auto-generated catch block
203             e.printStackTrace();
204         }
205         finally
206         {
207             DBUtil.close(state, conn);
208         }
209         return false;
210     }
211     
212     public boolean chose(String cnumber ){
213         //插入sql 语句
214         String sql="update classes set have = have +1 where cnumber = '"+cnumber+"'  ";
215         //选课修改语句:        
216         Connection conn =DBUtil.getConn();
217         Statement state=null;
218         try {
219             state=conn.createStatement();
220             state.executeUpdate(sql);
221         } catch (SQLException e) {
222             // TODO Auto-generated catch block
223             e.printStackTrace();
224         }
225         finally
226         {
227             DBUtil.close(state, conn);
228         }
229         return false;
230     }
231     public boolean unchose(String cnumber ){
232         //插入sql 语句
233         String sql="update classes set have = have -1 where cnumber = '"+cnumber+"'  ";
234         //选课修改语句:        
235         Connection conn =DBUtil.getConn();
236         Statement state=null;
237         try {
238             state=conn.createStatement();
239             state.executeUpdate(sql);
240         } catch (SQLException e) {
241             // TODO Auto-generated catch block
242             e.printStackTrace();
243         }
244         finally
245         {
246             DBUtil.close(state, conn);
247         }
248         return false;
249     }
250     public boolean judge(String cnumber){
251         //插入sql 语句
252         String sql="select * from classes where cnumber= '"+cnumber+"' ";
253         boolean flag =false;
254         Connection conn=DBUtil.getConn();
255         Statement state=null;
256         ResultSet rs=null;
257         try{
258             state=conn.createStatement();
259             rs=state.executeQuery(sql);
260             if(rs.next()) {//注意:这里用双引号,ID是表user里的ID列
261                 
262                 int most=rs.getInt("most");
263                 int have=rs.getInt("have");
264                 if(have<most) {
265                     flag=true;
266                 }
267                 //表示,把bean里的数据存入到list当中
268             }
269         }
270         catch (SQLException e)
271         {
272             e.printStackTrace();
273         }
274         finally
275         {
276             DBUtil.close(state, conn);
277         }
278         return flag;
279     }
280     
281     
282     public boolean update(Classes classes) {
283         //插入sql 语句
284         String sql="update classes set cname='"+classes.getCname()+"',most='"+classes.getMost()+"' where cnumber='"+classes.getCnumber()+"' ";
285         System.out.println(sql);
286         //update语句:
287         //update table_name set column1=value1,column2=value2  where some_column=some_value;
288         System.out.println(sql);
289         Connection conn=DBUtil.getConn();
290         Statement state=null;
291         
292         try {
293             state=conn.createStatement();
294             state.executeUpdate(sql);
295         } catch (SQLException e) {
296             // TODO Auto-generated catch block
297             e.printStackTrace();
298         }
299         finally
300         {
301             DBUtil.close(state, conn);
302         }
303         
304         return false;
305     }
306     public boolean update(String cteacher,String oldname) {
307         //插入sql 语句
308         String sql="update classes set cteacher='"+cteacher+"' where cteacher='"+oldname+"' ";
309         
310         //update语句:
311         //update table_name set column1=value1,column2=value2  where some_column=some_value;
312 
313         Connection conn=DBUtil.getConn();
314         Statement state=null;
315         
316         try {
317             state=conn.createStatement();
318             state.executeUpdate(sql);
319         } catch (SQLException e) {
320             // TODO Auto-generated catch block
321             e.printStackTrace();
322         }
323         finally
324         {
325             DBUtil.close(state, conn);
326         }
327         
328         return false;
329     }
330     public List<Classes> list(String tname){
331         //插入sql语句
332         String sql="select * from classes where cteacher = '"+tname+"' order by id asc";
333         
334         List<Classes>list=new ArrayList<>();
335         //给集合list创造(new)一个存储空间用于存放数据
336         
337         
338         Connection conn=DBUtil.getConn();
339         Statement state=null;
340         ResultSet rs=null;
341         
342         try{
343             state=conn.createStatement();
344             rs=state.executeQuery(sql);
345             Classes classes=null;
346             while(rs.next()) {//注意:这里用双引号,ID是表user里的ID列
347                 String cnumber=rs.getString("cnumber");
348                 String cname=rs.getString("cname");
349                 String cteacher=rs.getString("cteacher");
350                 int most=rs.getInt("most");
351                 int have=rs.getInt("have");
352                 classes=new Classes(cnumber,cname,cteacher,most,have);
353                 list.add(classes);
354                 //表示,把bean里的数据存入到list当中
355             }
356         }
357         catch (SQLException e)
358         {
359             e.printStackTrace();
360         }
361         finally
362         {
363             DBUtil.close(state, conn);
364         }
365         return list;
366     }
367     
368     public List<Classes> list(){
369         //插入sql语句
370         String sql="select * from classes order by id asc";
371         
372         List<Classes>list=new ArrayList<>();
373         //给集合list创造(new)一个存储空间用于存放数据
374         
375         
376         Connection conn=DBUtil.getConn();
377         Statement state=null;
378         ResultSet rs=null;
379         
380         try{
381             state=conn.createStatement();
382             rs=state.executeQuery(sql);
383             Classes classes=null;
384             while(rs.next()) {//注意:这里用双引号,ID是表user里的ID列
385                 String cnumber=rs.getString("cnumber");
386                 String cname=rs.getString("cname");
387                 String cteacher=rs.getString("cteacher");
388                 int most=rs.getInt("most");
389                 int have=rs.getInt("have");
390                 classes=new Classes(cnumber,cname,cteacher,most,have);
391                 list.add(classes);
392                 //表示,把bean里的数据存入到list当中
393             }
394         }
395         catch (SQLException e)
396         {
397             e.printStackTrace();
398         }
399         finally
400         {
401             DBUtil.close(state, conn);
402         }
403         return list;
404     }
405     
406     
407     
408     public boolean only(String cnumber) {
409         //定义标记
410         boolean flag=false;
411         //插入sql语句
412         String sql="select * from classes where cnumber = '"+cnumber+"'";
413         Connection conn=DBUtil.getConn();
414         Statement state=null;
415         ResultSet rs=null;
416         
417         try {
418             state=conn.createStatement();
419             rs=state.executeQuery(sql);
420             //要用statement类的executeQuery()方法来下达select指令以查询数据库,
421             //executeQuery()方法会把数据库响应的查询结果存放在ResultSet类对象中供我们使用。
422             while (rs.next()) {
423                 flag = true;
424             }
425             
426             
427         } catch (SQLException e) {
428             // TODO Auto-generated catch block
429             e.printStackTrace();
430         }finally {
431             DBUtil.close(rs, state, conn);
432         }
433         
434         return flag;
435     }
436 }
437 
438 
439 package Dao;
440 
441 import java.sql.Connection;
442 import java.sql.ResultSet;
443 import java.sql.SQLException;
444 import java.sql.Statement;
445 import java.util.ArrayList;
446 import java.util.List;
447 
448 import Bean.Login;
449 import DBUtil.DBUtil;
450 public class LoginDao {
451     
452     public boolean insert(Login login){
453         //插入的sql语句
454         String sql="insert into login(account,password) values('"+login.getAccount()+"','"+login.getPassword()+"')";
455         Connection conn=DBUtil.getConn();//添加数据库,加载驱动
456         Statement state=null;//创建statement对象并置空
457         try {
458             state=conn.createStatement();
459             state.executeUpdate(sql);
460         } catch (SQLException e) {
461             e.printStackTrace();
462         }
463         finally {
464             DBUtil.close(state, conn);
465         }
466         return false;
467     }
468     
469     public boolean delete(String account){
470         //插入sql 语句
471         String sql="delete from login where account='"+account+"' ";
472         String sql1="delete from student where account='"+account+"' ";
473         String sql2="delete from teacher where account='"+account+"' ";
474         //删除语句:
475         //delete from table_name where some_colume=some_value
476         
477         Connection conn =DBUtil.getConn();
478         Statement state=null;
479         try {
480             state=conn.createStatement();
481             state.executeUpdate(sql);
482             state.executeUpdate(sql1);
483             state.executeUpdate(sql2);
484         } catch (SQLException e) {
485             // TODO Auto-generated catch block
486             e.printStackTrace();
487         }
488         finally
489         {
490             DBUtil.close(state, conn);
491         }
492         return false;
493     }
494     
495     public boolean log(String account,String password){
496         //插入sql语句
497         String sql="select * from login where account='"+account+"' and password='"+password+"'";
498         //看数据库里面是否有数据,提取出来
499         Connection conn=DBUtil.getConn();
500         Statement state=null;
501         ResultSet rs=null;
502         boolean flag=false;
503         try{
504             state=conn.createStatement();
505             rs=state.executeQuery(sql);
506             if(rs.next()) {//注意:这里用双引号,ID是表user里的ID列
507                 flag=true;
508                 //表示,把bean里的数据存入到list当中
509             }
510         }
511         catch (SQLException e)
512         {
513             e.printStackTrace();
514         }
515         finally
516         {
517             DBUtil.close(state, conn);
518         }
519         return flag;
520     }
521     
522     
523 }
524 
525 
526 package Dao;
527 
528 import java.sql.Connection;
529 import java.sql.ResultSet;
530 import java.sql.SQLException;
531 import java.sql.Statement;
532 
533 import Bean.Student;
534 import Bean.Teacher;
535 import DBUtil.DBUtil;
536 
537 public class StudentDao {
538     public boolean insert(Student student){
539         String sql="insert into student(sname,snumber,ssex,sgrade,specialities) values('"+student.getSname()+"','"+student.getSnumber()+"','"+student.getSsex()+"','"+student.getSgrade()+"','"+student.getSpecialities()+"')";
540         
541         Connection conn=DBUtil.getConn();//添加数据库,加载驱动
542         Statement state=null;//创建statement对象并置空
543         try {
544             
545             //实例化statement对象  方便操作
546             state=conn.createStatement();
547             state.executeUpdate(sql);
548             //执行数据库更新操作用于执行insert、update或delete语句以及SQLDDL(数据定义语言)语句,
549             //例如creattable和droptable,(创建表和删除表)
550             
551         } catch (SQLException e) {
552             // TODO Auto-generated catch block
553             e.printStackTrace();
554         }
555         //finally作为异常处理的一部分,它只能用在try/catch语句中,并且附带一个语句块,表示这段语句最终一定会被执行(不管有没有抛出异常),
556         //经常被用在需要释放资源的情况下。
557         finally {
558             DBUtil.close(state, conn);//clase 释放资源
559         }
560         
561         return false;
562     }
563     
564     
565     public boolean update(Student student) {
566         //插入sql 语句
567         String sql="update student set sname='"+student.getSname()+"',password='"+student.getPassword()+"',ssex='"+student.getSsex()+"',sgrade='"+student.getSgrade()+"',specialities='"+student.getSpecialities()+"' where snumber='"+student.getSnumber()+"' ";
568         //update语句:
569         //update table_name set column1=value1,column2=value2  where some_column=some_value;
570         
571         Connection conn=DBUtil.getConn();
572         Statement state=null;
573         
574         try {
575             state=conn.createStatement();
576             state.executeUpdate(sql);
577         } catch (SQLException e) {
578             // TODO Auto-generated catch block
579             e.printStackTrace();
580         }
581         finally
582         {
583             DBUtil.close(state, conn);
584         }
585         
586         return false;
587     }
588     public Student log(String account,String password){
589         //插入sql语句
590         String sql="select * from student where snumber='"+account+"' and password='"+password+"'";
591         Student student=null;
592         Connection conn=DBUtil.getConn();
593         Statement state=null;
594         ResultSet rs=null;
595         boolean flag=false;
596         try{
597             state=conn.createStatement();
598             rs=state.executeQuery(sql);
599             if(rs.next()) {//注意:这里用双引号,ID是表user里的ID列
600                 String sname=rs.getString("sname");
601                 String snumber=rs.getString("snumber");
602                 String ssex=rs.getString("ssex");
603                 String sgrade=rs.getString("sgrade");
604                 String specialities=rs.getString("specialities");
605                 student=new Student(sname, snumber, ssex, sgrade, specialities);
606                 
607                 //表示,把bean里的数据存入到list当中
608             }
609         }
610         catch (SQLException e)
611         {
612             e.printStackTrace();
613         }
614         finally
615         {
616             DBUtil.close(state, conn);
617         }
618         return student;
619     }
620 }
621 
622 
623 package Dao;
624 
625 import java.sql.Connection;
626 import java.sql.ResultSet;
627 import java.sql.SQLException;
628 import java.sql.Statement;
629 
630 import Bean.Teacher;
631 import DBUtil.DBUtil;
632 
633 public class TeacherDao {
634     public boolean insert(Teacher teacher){
635         String sql="insert into teacher(tname,tnumber,tsex,tacademy,twork) values('"+teacher.getTname()+"','"+teacher.getTnumber()+"','"+teacher.getTsex()+"','"+teacher.getTacademy()+"','"+teacher.getTwork()+"')";
636         
637         Connection conn=DBUtil.getConn();//添加数据库,加载驱动
638         Statement state=null;//创建statement对象并置空
639         try {
640             
641             //实例化statement对象  方便操作
642             state=conn.createStatement();
643             state.executeUpdate(sql);
644             //执行数据库更新操作用于执行insert、update或delete语句以及SQLDDL(数据定义语言)语句,
645             //例如creattable和droptable,(创建表和删除表)
646             
647         } catch (SQLException e) {
648             // TODO Auto-generated catch block
649             e.printStackTrace();
650         }
651         //finally作为异常处理的一部分,它只能用在try/catch语句中,并且附带一个语句块,表示这段语句最终一定会被执行(不管有没有抛出异常),
652         //经常被用在需要释放资源的情况下。
653         finally {
654             DBUtil.close(state, conn);//clase 释放资源
655         }
656         
657         return true;
658     }
659     
660     
661     public boolean update(Teacher teacher) {
662         //插入sql 语句
663         String sql="update teacher set tname='"+teacher.getTname()+"',password='"+teacher.getPassword()+"',tsex='"+teacher.getTsex()+"',tacademy='"+teacher.getTacademy()+"',twork='"+teacher.getTwork()+"' where tnumber='"+teacher.getTnumber()+"' ";
664         //update语句:
665         //update table_name set column1=value1,column2=value2  where some_column=some_value;
666         
667         Connection conn=DBUtil.getConn();
668         Statement state=null;
669         
670         try {
671             state=conn.createStatement();
672             state.executeUpdate(sql);
673         } catch (SQLException e) {
674             // TODO Auto-generated catch block
675             e.printStackTrace();
676         }
677         finally
678         {
679             DBUtil.close(state, conn);
680         }
681         
682         return false;
683     }
684     
685     
686     public Teacher log(String account,String password){
687         //插入sql语句
688         String sql="select * from teacher where tnumber='"+account+"' and password='"+password+"'";
689         Teacher teacher=null;
690         Connection conn=DBUtil.getConn();
691         Statement state=null;
692         ResultSet rs=null;
693         try{
694             state=conn.createStatement();
695             rs=state.executeQuery(sql);
696             if(rs.next()) {//注意:这里用双引号,ID是表user里的ID列
697                 String tname=rs.getString("tname");
698                 String tnumber=rs.getString("tnumber");
699                 String tsex=rs.getString("tsex");
700                 String tacademy=rs.getString("tacademy");
701                 String twork=rs.getString("twork");
702                 teacher=new Teacher(tname, tnumber, tsex, tacademy, twork);
703                 //表示,把bean里的数据存入到list当中
704             }
705         }
706         catch (SQLException e)
707         {
708             e.printStackTrace();
709         }
710         finally
711         {
712             DBUtil.close(state, conn);
713         }
714         
715         return teacher;
716     }
717 }
718 
719 Dao
Dao
 1 package DBUtil;
 2 
 3 import java.sql.Connection;
 4 import java.sql.DriverManager;
 5 import java.sql.ResultSet;
 6 import java.sql.SQLException;
 7 import java.sql.Statement;
 8 
 9 public class DBUtil{
10     //sql语句字符串
11     public static String db_url="jdbc:mysql://localhost:3306/chooseclass?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = xuanke";
12     //数据库名
13     public static String db_name="root";
14     //数据库密码
15     public static String db_password="15732767817lxy11";
16     
17     public static Connection getConn() {
18         //声明connection类型对象,指向空
19         Connection conn=null;
20         
21         //连接驱动
22         //链接数据库
23         try {
24             //驱动程序名
25             Class.forName("com.mysql.cj.jdbc.Driver");
26             //具体地连接到数据库——联接字符串(数据库名),联接用户名,联接密码名
27             conn =DriverManager.getConnection(db_url, db_name, db_password);
28         } catch (Exception e) {
29             // TODO Auto-generated catch block
30             e.printStackTrace();
31         }
32         return conn;
33     }
34     public static void close(Statement state, Connection conn) {
35         if(state !=null) {
36             try {
37                 state.close();
38             } catch (SQLException e) {
39                 // TODO Auto-generated catch block
40                 e.printStackTrace();
41             }
42         }
43         if(conn!=null) {
44             try {
45                 conn.close();
46             } catch (SQLException e) {
47                 // TODO Auto-generated catch block
48                 e.printStackTrace();
49             }
50         }
51     }
52     
53     public static void close(ResultSet rs,Statement state, Connection conn) {
54         if(rs!=null) {
55             try {
56                 rs.close();
57             } catch (SQLException e) {
58                 // TODO Auto-generated catch block
59                 e.printStackTrace();
60             }
61         }
62         
63         if(state!=null) {
64             try {
65                 state.close();
66             } catch (SQLException e) {
67                 // TODO Auto-generated catch block
68                 e.printStackTrace();
69             }
70         }
71         
72         if(conn!=null) {
73             try {
74                 conn.close();
75             } catch (SQLException e) {
76                 // TODO Auto-generated catch block
77                 e.printStackTrace();
78             }
79         }
80         
81         
82     }
83     
84 }
85 
86 DB
DBUti
  1 package Servlet;
  2 
  3 import java.io.IOException;
  4 import javax.servlet.ServletException;
  5 import javax.servlet.annotation.WebServlet;
  6 import javax.servlet.http.HttpServlet;
  7 import javax.servlet.http.HttpServletRequest;
  8 import javax.servlet.http.HttpServletResponse;
  9 
 10 import Bean.Classes;
 11 import Bean.Student;
 12 import Bean.Teacher;
 13 import Dao.ChooseDao;
 14 import Dao.ClassesDao;
 15 import Dao.StudentDao;
 16 import Dao.TeacherDao;
 17 
 18 /**
 19  * Servlet implementation class AddServlet
 20  */
 21 @WebServlet("/addServlet")
 22 public class AddServlet extends HttpServlet {
 23     
 24     public AddServlet() {
 25         super();
 26         // TODO Auto-generated constructor stub
 27     }
 28     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
 29         req.setCharacterEncoding("utf-8");//设置从jsp或HTML中请求数据的值,也就是设置为中文,防止乱码
 30         String method=req.getParameter("method");//getParameter()获取的是客户端设置的数据。
 31         if(method.equals("teacher")) {
 32             String tname=req.getParameter("name");
 33             String tsex=req.getParameter("sex");
 34             String tnumber=req.getParameter("tnumber");
 35             String tacademy=req.getParameter("tacademy");
 36             String twork=req.getParameter("twork");
 37             Teacher teacher=new Teacher(tname, tnumber, tsex, tacademy, twork);
 38             TeacherDao TD=new TeacherDao();
 39             if(TD.insert(teacher)) {
 40                 //如果添加成功
 41                 req.setAttribute("message", "添加成功");
 42                 //这里表示,在req的作用域中设置一个massage变量,变量内容是:添加成功
 43                 //然后,当跳转到它下一个界面时,这个作用域里的值可以通过Object message =request.getAttribute("message")拿出来使用
 44                 req.getRequestDispatcher("admin.jsp").forward(req, resp);
 45             }
 46             else {
 47                 //处理失败
 48                 req.setAttribute("message", "添加重复,请重新输入");
 49                 req.getRequestDispatcher("addTeacher.jsp").forward(req, resp);
 50             }
 51         }
 52         else if(method.equals("student")) {
 53             String sname=req.getParameter("sname");
 54             String ssex=req.getParameter("sex");
 55             String snumber=req.getParameter("snumber");
 56             String sgrade=req.getParameter("sgrade");
 57             String specialities=req.getParameter("specialities");
 58             Student student=new Student(sname, snumber, ssex, sgrade, specialities);
 59             StudentDao SD=new StudentDao();
 60             if(SD.insert(student)) {
 61                 //如果添加成功
 62                 req.setAttribute("message", "添加成功");
 63                 //这里表示,在req的作用域中设置一个massage变量,变量内容是:添加成功
 64                 //然后,当跳转到它下一个界面时,这个作用域里的值可以通过Object message =request.getAttribute("message")拿出来使用
 65                 req.getRequestDispatcher("admin.jsp").forward(req, resp);
 66             }
 67             else {
 68                 //处理失败
 69                 req.setAttribute("message", "添加重复,请重新输入");
 70                 req.getRequestDispatcher("addStudent.jsp").forward(req, resp);
 71             }
 72         }
 73         else if(method.equals("class")) {
 74             String cname=req.getParameter("cname");
 75             String cnumber=req.getParameter("cnumber");
 76             String cteacher=req.getParameter("cteacher");
 77             String most=req.getParameter("most");
 78             int a=Integer.parseInt(most);
 79             Classes classes=new Classes(cnumber,cname,cteacher,a);
 80             ClassesDao cD = new ClassesDao();
 81             if(cD.insert(classes)) {
 82                 //如果添加成功
 83                 req.setAttribute("message", "添加成功");
 84                 //这里表示,在req的作用域中设置一个massage变量,变量内容是:添加成功
 85                 //然后,当跳转到它下一个界面时,这个作用域里的值可以通过Object message =request.getAttribute("message")拿出来使用
 86                 req.getRequestDispatcher("teacher.jsp").forward(req, resp);
 87             }
 88             else {
 89                 //处理失败
 90                 req.setAttribute("message", "添加重复,请重新输入");
 91                 req.getRequestDispatcher("teacherAddClass.jsp").forward(req, resp);
 92             }
 93         }
 94         else if(method.equals("choose")) {
 95             String snumber=req.getParameter("snumber");
 96             String sname=req.getParameter("sname");
 97             String cname=req.getParameter("cname");
 98             String cnumber=req.getParameter("cnumber");
 99             String cteacher=req.getParameter("cteacher");
100             String most=req.getParameter("most");
101             String have=req.getParameter("have");
102             int a=Integer.parseInt(most);
103             int b=Integer.parseInt(have);
104             Classes classes=new Classes(cnumber,cname,cteacher,a);
105             ChooseDao chD=new ChooseDao();
106             if((a>b)&&chD.insert(snumber,sname,classes)) {
107                 //如果添加成功
108                 req.setAttribute("message", "添加成功");
109                 //这里表示,在req的作用域中设置一个massage变量,变量内容是:添加成功
110                 //然后,当跳转到它下一个界面时,这个作用域里的值可以通过Object message =request.getAttribute("message")拿出来使用
111                 req.getRequestDispatcher("selectServlet?method=class").forward(req, resp);
112             }
113             else {
114                 //处理失败
115                 req.setAttribute("message", "添加重复或所选课容量已满");
116                 req.getRequestDispatcher("selectServlet?method=class").forward(req, resp);
117             }
118         }
119         
120         
121         
122     }
123     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
124         // TODO Auto-generated method stub
125         doGet(request, response);
126     }
127 
128 }
129 
130 package Servlet;
131 
132 import java.io.IOException;
133 import javax.servlet.ServletException;
134 import javax.servlet.annotation.WebServlet;
135 import javax.servlet.http.HttpServlet;
136 import javax.servlet.http.HttpServletRequest;
137 import javax.servlet.http.HttpServletResponse;
138 
139 import Dao.ChooseDao;
140 import Dao.ClassesDao;
141 
142 /**
143  * Servlet implementation class DeleteServlet
144  */
145 @WebServlet("/deleteServlet")
146 public class DeleteServlet extends HttpServlet {
147     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
148         
149         String method=req.getParameter("method");
150         if(method.equals("sdclass")) {
151             String cnumber=req.getParameter("cnumber");
152             String snumber=req.getParameter("snumber");
153             ChooseDao chD=new ChooseDao();
154             ClassesDao cD=new ClassesDao();
155             if(chD.id(snumber, cnumber)) {
156                 chD.delete(snumber, cnumber);
157                 cD.unchose(cnumber);
158                 req.setAttribute("message", "取消选课成功");
159                 req.getRequestDispatcher("selectServlet?method=class").forward(req, resp);
160             }
161             else {
162                 req.setAttribute("message", "未选课,取消选课失败");
163                 req.getRequestDispatcher("selectServlet?method=class").forward(req, resp);
164             }
165             
166         }
167         if(method.equals("tdclass")) {
168             String cnumber=req.getParameter("cnumber");
169             String cname=req.getParameter("cname");
170             String tname=req.getParameter("tname");
171             ChooseDao chD=new ChooseDao();
172             ClassesDao cD=new ClassesDao();
173             chD.delete( cnumber);
174             cD.delete(cnumber, cname);
175             req.setAttribute("message", "删除课程成功");
176             req.getRequestDispatcher("updateServlet?method=classlist").forward(req, resp);
177         }
178         if(method.equals("tsclass")) {
179             String cnumber=req.getParameter("cnumber");
180             String cname=req.getParameter("cname");
181             String tname=req.getParameter("tname");
182             ChooseDao chD=new ChooseDao();
183             ClassesDao cD=new ClassesDao();
184             chD.delete( cnumber);
185             cD.delete(cnumber, cname);
186             req.setAttribute("message", "删除课程成功");
187             req.getRequestDispatcher("updateServlet?method=sclasslist").forward(req, resp);
188         }
189         
190         
191     }
192 
193     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
194         // TODO Auto-generated method stub
195         doGet(request, response);
196     }
197 
198 }
199 
200 
201 package Servlet;
202 
203 import java.io.IOException;
204 import javax.servlet.ServletException;
205 import javax.servlet.annotation.WebServlet;
206 import javax.servlet.http.HttpServlet;
207 import javax.servlet.http.HttpServletRequest;
208 import javax.servlet.http.HttpServletResponse;
209 
210 import Bean.Student;
211 import Bean.Teacher;
212 import Dao.LoginDao;
213 import Dao.StudentDao;
214 import Dao.TeacherDao;
215 
216 
217 @WebServlet("/loginServlet")
218 public class LoginServlet extends HttpServlet {
219     public LoginServlet() {
220         super();
221     }
222     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
223         
224         LoginDao login=new LoginDao();
225         TeacherDao tD=new TeacherDao();
226         StudentDao sD=new StudentDao();
227         String number=request.getParameter("account");
228         String password=request.getParameter("password");
229         String account=request.getParameter("account");
230         if(number.length()==6) {
231             
232             if(login.log(account, password)) {
233                 Teacher teacher=null;
234                 teacher=tD.log(account, password);
235                 request.getSession().setAttribute("teacher", teacher);
236                 request.setAttribute("message", "恭喜"+teacher.getTname()+"登陆成功");
237                 request.getRequestDispatcher("teacher.jsp").forward(request, response);
238                 }
239             else {
240                 request.setAttribute("message", "账号或密码错误");
241                 request.getRequestDispatcher("index.jsp").forward(request, response);
242             }
243         }else if(number.length()==8) {
244             
245             if(login.log(account, password)) {
246                 Student student=null;
247                 student=sD.log(account, password);
248                 request.getSession().setAttribute("student", student);
249                 request.setAttribute("message", "恭喜"+student.getSname()+"登陆成功");
250                 request.getRequestDispatcher("student.jsp").forward(request, response);
251                 }
252             else {
253                 request.setAttribute("message", "账号或密码错误");
254                 request.getRequestDispatcher("index.jsp").forward(request, response);
255             }
256             
257         }
258         else if(number.equals("admin")) {
259             if(password.equals("123456")) {
260                 request.setAttribute("message", "登陆成功");
261                 request.getRequestDispatcher("admin.jsp").forward(request, response);
262             }
263         }
264     }
265     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
266         
267         doGet(request, response);
268     }
269 
270 }
271 
272 
273 package Servlet;
274 
275 import java.io.IOException;
276 import java.util.List;
277 
278 import javax.servlet.ServletException;
279 import javax.servlet.annotation.WebServlet;
280 import javax.servlet.http.HttpServlet;
281 import javax.servlet.http.HttpServletRequest;
282 import javax.servlet.http.HttpServletResponse;
283 
284 import Bean.ChooseClass;
285 import Bean.Classes;
286 import Dao.ChooseDao;
287 import Dao.ClassesDao;
288 
289 /**
290  * Servlet implementation class SelectServlet
291  */
292 @WebServlet("/selectServlet")
293 public class SelectServlet extends HttpServlet {
294     
295     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
296         ClassesDao cD =new ClassesDao();
297         ChooseDao chD=new ChooseDao();
298         
299         String method=req.getParameter("method");
300         if(method.equals("class")) {
301             List<Classes> class_list =cD.list();
302             req.setAttribute("class_list", class_list);
303             req.getRequestDispatcher("studentChoose.jsp").forward(req, resp);
304         }
305         else if(method.equals("teacherSC")) {
306             String tname=req.getParameter("tname");
307             List<Classes> class_list =cD.list(tname);
308             req.setAttribute("class_list", class_list);
309             req.getRequestDispatcher("teacherSelectClass.jsp").forward(req, resp);
310         }
311         else if(method.equals("SSC")) {
312             String cnumber=req.getParameter("cnumber");
313             System.out.println(cnumber);
314             List<ChooseClass> class_list =chD.list(cnumber);
315             req.setAttribute("class_list", class_list);
316             req.getRequestDispatcher("teacherChooseClass.jsp").forward(req, resp);
317         }
318         
319     }
320 
321     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
322     
323         doGet(request, response);
324     }
325 
326 }
327 
328 
329 package Servlet;
330 
331 import java.io.IOException;
332 import java.util.List;
333 
334 import javax.servlet.ServletException;
335 import javax.servlet.annotation.WebServlet;
336 import javax.servlet.http.HttpServlet;
337 import javax.servlet.http.HttpServletRequest;
338 import javax.servlet.http.HttpServletResponse;
339 
340 import Bean.Classes;
341 import Bean.Student;
342 import Bean.Teacher;
343 import Dao.ChooseDao;
344 import Dao.ClassesDao;
345 import Dao.StudentDao;
346 import Dao.TeacherDao;
347 
348 /**
349  * Servlet implementation class UpdateServlet
350  */
351 @WebServlet("/updateServlet")
352 public class UpdateServlet extends HttpServlet {
353     private static final long serialVersionUID = 1L;
354     
355     public UpdateServlet() {
356         super();
357         // TODO Auto-generated constructor stub
358     }
359     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
360         req.setCharacterEncoding("utf-8");
361         String method=req.getParameter("method");
362         if(method.equals("teacher")) {
363             String tname=req.getParameter("tname");
364             String tsex=req.getParameter("tsex");
365             String tnumber=req.getParameter("tnumber");
366             String tacademy=req.getParameter("tacademy");
367             String twork=req.getParameter("twork");
368             String oldname=req.getParameter("oldname");
369             Teacher teacher=new Teacher(tname, tnumber, tsex, tacademy, twork);
370             TeacherDao TD=new TeacherDao();
371             ClassesDao cD=new ClassesDao();
372             TD.update(teacher);
373             cD.update(tname, oldname);
374             //对数据库进行修改;
375             req.setAttribute("message", "修改成功");
376             req.getSession().setAttribute("teacher", teacher);
377             req.getRequestDispatcher("teacher.jsp").forward(req,resp);
378         }
379         else if(method.equals("student")) {
380             String sname=req.getParameter("sname");
381             String snumber=req.getParameter("snumber");
382             String password=req.getParameter("password");
383             String ssex=req.getParameter("ssex");
384             String sgrade=req.getParameter("sgrade");
385             String specialities=req.getParameter("specialities");
386             Student student=new Student(sname, snumber, password,ssex,sgrade, specialities);
387             StudentDao sD = new StudentDao();
388             sD.update(student);
389             //对数据库进行修改;
390             req.setAttribute("message", "修改成功");
391             req.getSession().setAttribute("student", student);
392             req.getRequestDispatcher("student.jsp").forward(req,resp);
393         }
394         else if(method.equals("classlist")) {
395             ClassesDao cD = new ClassesDao();
396             //List<Classes> class_list = cD.list((String) req.getSession().getAttribute("teacher.tname"));
397             String tn=req.getParameter("tname");
398             List<Classes> class_list = cD.list(tn);
399             req.getSession().setAttribute("class_list", class_list);
400             req.getRequestDispatcher("classUpdate.jsp").forward(req,resp);
401         }
402         else if(method.equals("sclasslist")) {
403             ClassesDao cD = new ClassesDao();
404             //List<Classes> class_list = cD.list((String) req.getSession().getAttribute("teacher.tname"));
405             String tn=req.getParameter("tname");
406             List<Classes> class_list = cD.list(tn);
407             req.getSession().setAttribute("class_list", class_list);
408             req.getRequestDispatcher("teacherSelectClass.jsp").forward(req,resp);
409         }
410         else if(method.equals("class")) {
411             String cname=req.getParameter("cname");
412             String cnumber=req.getParameter("cnumber");
413             String cteacher=req.getParameter("cteacher");
414             String most=req.getParameter("most");
415             int a=Integer.parseInt(most);
416             Classes cl =new Classes(cnumber, cname,cteacher,a);
417             ClassesDao cD = new ClassesDao();
418             cD.update(cl);
419             //对数据库进行修改;
420             req.setAttribute("message", "修改成功");
421             req.getSession().setAttribute("cl", cl);
422             req.getRequestDispatcher("teacher.jsp").forward(req,resp);
423         }
424         
425         
426         
427         
428     }
429     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
430         // TODO Auto-generated method stub
431         doGet(request, response);
432     }
433 
434 }
435 
436 servlet
Servlet

jsp代码略

posted @ 2020-11-22 14:27  大雄的脑袋  阅读(408)  评论(0编辑  收藏  举报