选课2.0
main.jsp:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登录系统</title> </head> <form id="1" action ="denlv.jsp" method="get"> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br> 身份: <select size ="1"name="calss"> <option value ="学生" selected>学生</option> <option value ="教师" >教师</option> <option value ="管理员" >管理员</option> </select> <br><br> 账号: <input type="text" name="num"size="15"/> <br><br> 密码: <input type="password" name="pass"size="16"/> <br><br> <br><br> <input type="submit" value="登录"/> <input type="reset" value="重置"/> </p> </form> </html>
denlv.jsp
<%@page import="aD.Ac"%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登录处理</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String calss=(String)request.getParameter("calss"); session.setAttribute("calss", calss); String num=(String)request.getParameter("num"); session.setAttribute("num", num); String pass=(String)request.getParameter("pass"); session.setAttribute("pass", pass); if(util.queryEmpty(num, pass)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else if(util.inquiryNumber(num,calss)){ out.print("<script language ='javaScript'> alert('未查询到改账号');window.history.back(-1); </script>"); }else if(util.denlv(calss, num, pass)){ out.print("<script language ='javaScript'> alert('密码错误');window.history.back(-1); </script>"); }else{ out.print("<script language='javaScript'> alert('登录成功');</script>"); if(calss.equals("教师")){ response.setHeader("refresh", "0;url=teacher.jsp"); }else if(calss.equals("学生")){ response.setHeader("refresh", "0;url=student.jsp"); }else if(calss.equals("管理员")){ response.setHeader("refresh", "0;url=contrul.jsp"); } } %> </body> </html>
contrul.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教师系统</title> </head> <p style="text-align:center;color:black;font-family:宋体,serif; font-size:20px"> <a>管理员</a> <br> <br><br> <input type="button" value="添加教师" onclick="location.href='NewTeacher.jsp'" /> <br><br> <input type="button" value="添加学生" onclick="location.href='addStudent.jsp'" /> <br><br> <input type="button" value="登出" onclick="location.href='main.jsp'" /> </p> </html>
classKan.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>课程信息</title> </head> <body> <table border="1"style="text-align:center"> <caption>课程信息</caption> <tr> <td align="center" width=2%>课程编号</td> <td align="center" width=3%>课程名称</td> <td align="center" width=2%>任课老师</td> <td align="center" width=2%>已选人数</td> <td align="center" width=3%>人数上限</td> </tr> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String a=request.getParameter("id"); try{ Connection connect = util.sjk(); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from classim"); while(rs.next()){ if(a.equals(rs.getObject(1).toString())) { %> <tr> <td width=2% align="center"><%=rs.getObject(1) %></td> <td width=3% align="center"><%=rs.getObject(2) %></td> <td width=2% align="center"><%=rs.getObject(4) %></td> <td width=2% align="center"><%=rs.getObject(5) %></td> <td width=3% align="center"><%=rs.getObject(3) %></td> </tr> <% } } rs.close(); connect.close(); stmt.close(); }catch (SQLException e) { e.printStackTrace(); } %> </table> </body> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> </p> </html>
addstudentback.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>添加教师</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String calss="学生"; String num=(String)request.getParameter("num"); String name=(String)request.getParameter("name"); String sex=(String)request.getParameter("sex"); String banji=(String)request.getParameter("banji"); String zhuanye=(String)request.getParameter("zhuanye"); if(util.query(num)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else if(util.numCha(num)){ out.print("<script language ='javaScript'> alert('学号必须为8位,且必须是数字');window.history.back(-1); </script>"); }else if(util.queryTeacherxiu(name, sex, banji, zhuanye)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else if(util.addStudentNum(num)){ out.print("<script language ='javaScript'> alert('学号重复');window.history.back(-1); </script>"); }else{ util.addStudent(calss, num, name, sex, banji, zhuanye); out.print("<script language='javaScript'> alert('添加成功');</script>"); response.setHeader("refresh", "0;url=contrul.jsp"); } %> </body> </html>
NewTeacher.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>添加教师</title> </head> <form id="1" action ="NewTeacherback.jsp" method="get"> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br> 工号: <input type="text" name="num"size="15"/> <br><br> 姓名: <input type="text" name="name"size="15"/> <br><br> 性别: <input type="text" name="sex"size="15"/> <br><br> 学院: <input type="text" name="yuan"size="15"/> <br><br> 职称: <select size ="1"name="zhichen"> <option value ="教授" selected>教授</option> <option value ="副教授">副教授</option> <option value ="讲师" >讲师</option> <option value ="助教" >助教</option> </select> <br><br> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> <br><br> <input type="submit" value="确认"/> <input type="reset" value="重置"/> </p> </form> </html>
NewTeacherback.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>添加教师</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String calss="教师"; String num=(String)request.getParameter("num"); String name=(String)request.getParameter("name"); String sex=(String)request.getParameter("sex"); String yuan=(String)request.getParameter("yuan"); String zhichen=(String)request.getParameter("zhichen"); if(util.query(num)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else if(util.numCha(num)){ out.print("<script language ='javaScript'> alert('工号必须为8位,且必须是数字');window.history.back(-1); </script>"); }else if(util.queryTeacherxiu(name, sex, yuan, zhichen)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else if(util.addTeacherNum(num)){ out.print("<script language ='javaScript'> alert('工号重复');window.history.back(-1); </script>"); }else{ util.addTeaher(calss, num, name, sex, yuan, zhichen); out.print("<script language='javaScript'> alert('添加成功');</script>"); response.setHeader("refresh", "0;url=contrul.jsp"); } %> </body> </html>
student.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>学生系统</title> </head> <p style="text-align:center;color:black;font-family:宋体,serif; font-size:20px"> <a>学生系统</a> <br> <br><br> <input type="button" value="修改个人信息" onclick="location.href='student-resive.jsp'" /> <br><br> <input type="button" value="浏览课程" onclick="location.href='Swatch-c.jsp'" /> <br><br> <input type="button" value="选课" onclick="location.href='xuanke.jsp'" /> <br><br> <input type="button" value="修改密码" onclick="location.href='sxiu.jsp'" /> <br><br> <input type="button" value="登出" onclick="location.href='main.jsp'" /> </p> </html>
student-resive.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>修改</title> </head> <body> <table border="1"style="text-align:center"> <caption>学生信息</caption> <tr> <td align="center" width=3%>学号</td> <td align="center" width=3%>姓名</td> <td align="center" width=2%>性别</td> <td align="center" width=2%>班级</td> <td align="center" width=3%>专业</td> </tr> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String num=session.getAttribute("num").toString(); try{ Connection connect = util.sjk(); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from student"); while(rs.next()){ if(num.equals(rs.getObject(2).toString())) { %> <tr> <td width=3% align="center"><%=rs.getObject(2) %></td> <td width=3% align="center"><%=rs.getObject(3) %></td> <td width=2% align="center"><%=rs.getObject(4) %></td> <td width=2% align="center"><%=rs.getObject(5) %></td> <td width=3% align="center"><%=rs.getObject(6) %></td> </tr> <% } } rs.close(); connect.close(); stmt.close(); }catch (SQLException e) { e.printStackTrace(); } %> </table> </body> <form id="1" action ="student-resiveback.jsp" method="get"> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br> 姓名: <input type="text" name="name"size="15"/> <br><br> 性别: <input type="text" name="sex"size="15"/> <br><br> 班级: <input type="text" name="banji"size="15"/> <br><br> 专业: <input type="text" name="zhuanye"size="15"/> <br><br> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> <br><br> <input type="submit" value="修改"/> <input type="reset" value="重置"/> </p> </form> </html>
student-resiveback.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>修改信息</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String calss=session.getAttribute("calss").toString(); String num=session.getAttribute("num").toString(); String name=(String)request.getParameter("name"); String sex=(String)request.getParameter("sex"); String yuan=(String)request.getParameter("banji"); String zhichen=(String)request.getParameter("zhuanye"); String num1=num; if(util.queryTeacherxiu(name, sex, yuan, zhichen)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else{ util.studentXiugai(calss, num, name, sex, yuan, zhichen, num1); out.print("<script language='javaScript'> alert('修改成功');</script>"); response.setHeader("refresh", "0;url=student.jsp"); } %> </body> </html>
Swatch-c.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>浏览</title> </head> <body> <table border="1"style="text-align:center"> <caption>课程信息</caption> <tr> <td align="center" width=3%>课程编号</td> <td align="center" width=3%>课程名字</td> <td align="center" width=3%>教师</td> </tr> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% try{ Connection connect = util.sjk(); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from classim"); while(rs.next()){ %> <tr> <td width=3% align="center"><%=rs.getObject(1) %></td> <td width=3% align="center"><a style="color:blue" href='classKan.jsp?id=<%=rs.getObject(1) %>'><%=rs.getObject(2)%></a></td> <td width=3% align="center"><a style="color:blue" href='teacherKan.jsp?id=<%=rs.getObject(6) %>'><%=rs.getObject(4)%></a></td> </tr> <% } rs.close(); connect.close(); stmt.close(); }catch (SQLException e) { e.printStackTrace(); } %> </table> </body> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> </p> </html>
sxiu.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>修改</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <form id="1" action ="sxiuback.jsp" method="get"> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br> 输入旧密码: <input type="text" name="jiu"size="15"/> <br><br> 输入新密码: <input type="text" name="xin"size="15"/> <br><br> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> <br><br> <input type="submit" value="修改"/> <input type="reset" value="重置"/> </p> </form> </body> </html>
sxiuback.jsp
<%@page import="aD.Ac"%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>处理</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String calss="学生"; String num=session.getAttribute("num").toString(); String pass=session.getAttribute("pass").toString(); String jiu=(String)request.getParameter("jiu"); String xin=(String)request.getParameter("xin"); if(util.queryEmpty(jiu, xin)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else if(!pass.equals(jiu)){ out.print("<script language ='javaScript'> alert('旧密码错误');window.history.back(-1); </script>"); }else if(util.numCha(xin)){ out.print("<script language ='javaScript'> alert('新密码必须为8位,且必须是数字');window.history.back(-1); </script>"); }else{ util.XiuM(xin, num, calss); out.print("<script language='javaScript'> alert('修改成功');</script>"); response.setHeader("refresh", "0;url=student.jsp"); } %> </body> </html>
teacher.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教师系统</title> </head> <p style="text-align:center;color:black;font-family:宋体,serif; font-size:20px"> <a>教师系统</a> <br> <br><br> <input type="button" value="添加课程" onclick="location.href='teacher-addclass.jsp'" /> <br><br> <input type="button" value="修改个人信息" onclick="location.href='teacher-revise.jsp'" /> <br><br> <input type="button" value="浏览选课学生信息" onclick="location.href='teacher-watch.jsp'" /> <br><br> <input type="button" value="修改密码" onclick="location.href='Txiu.jsp'" /> <br><br> <input type="button" value="登出" onclick="location.href='main.jsp'" /> </p> </html>
teacher-addback.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>添加课程</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String num=session.getAttribute("num").toString(); String classnum=(String)request.getParameter("classnum"); String classname=(String)request.getParameter("classname"); String classmax=(String)request.getParameter("classmax"); String classteacher=session.getAttribute("name").toString(); String classnow="0"; if(util.queryTeacherAdd(classnum, classname,classmax)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else if(util.classnumCha(classnum)){ out.print("<script language ='javaScript'> alert('课程编号应为6位数字');window.history.back(-1); </script>"); }else if(util.classnumchong(classnum)){ out.print("<script language ='javaScript'> alert('课程编号已存在');window.history.back(-1); </script>"); }else if(util.pin(classmax)){ out.print("<script language ='javaScript'> alert('人数上限应为正整数');window.history.back(-1); </script>"); }else if(util.classxichong(classname, classteacher)){ out.print("<script language ='javaScript'> alert('课程重复,与您已有课程重复');window.history.back(-1); </script>"); }else{ util.inputClassT(classnum, classname, classmax, classteacher, classnow,num); out.print("<script language='javaScript'> alert('添加成功');</script>"); response.setHeader("refresh", "0;url=teacher.jsp"); } %> </body> </html>
teacher-addclass.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>添加课程</title> </head> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String calss=session.getAttribute("calss").toString(); String num=session.getAttribute("num").toString(); String name=util.namereturn(calss, num); session.setAttribute("name", name); %> <form id="1" action ="teacher-addback.jsp" method="get"> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br> 课程编号: <input type="text" name="classnum"size="15"/> <br><br> 课程名称: <input type="text" name="classname"size="15"/> <br><br> 选课人数上限: <input type="text" name="classmax"size="15"/> <br><br> 任课教师: <% out.println(name); %> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> <br><br> <input type="submit" value="添加"/> <input type="reset" value="重置"/> </p> </form> </html>
teacherKan.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>教师信息</title> </head> <body> <table border="1"style="text-align:center"> <caption>教师信息</caption> <tr> <td align="center" width=2%>教师工号</td> <td align="center" width=3%>教师姓名</td> <td align="center" width=2%>教师性别</td> <td align="center" width=3%>教师院系</td> <td align="center" width=2%>教师职位</td> </tr> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String a=request.getParameter("id"); try{ Connection connect = util.sjk(); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from teacher"); while(rs.next()){ if(a.equals(rs.getObject(2).toString())) { %> <tr> <td width=2% align="center"><%=rs.getObject(2) %></td> <td width=3% align="center"><%=rs.getObject(3) %></td> <td width=2% align="center"><%=rs.getObject(4) %></td> <td width=3% align="center"><%=rs.getObject(5) %></td> <td width=2% align="center"><%=rs.getObject(6) %></td> </tr> <% } } rs.close(); connect.close(); stmt.close(); }catch (SQLException e) { e.printStackTrace(); } %> </table> </body> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> </p> </html>
teacher-revise.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>修改</title> </head> <body> <table border="1"style="text-align:center"> <caption>教师信息</caption> <tr> <td align="center" width=3%>工号</td> <td align="center" width=3%>姓名</td> <td align="center" width=2%>性别</td> <td align="center" width=2%>学院</td> <td align="center" width=3%>职称</td> </tr> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String num=session.getAttribute("num").toString(); try{ Connection connect = util.sjk(); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from teacher"); while(rs.next()){ if(num.equals(rs.getObject(2).toString())) { %> <tr> <td width=3% align="center"><%=rs.getObject(2) %></td> <td width=3% align="center"><%=rs.getObject(3) %></td> <td width=2% align="center"><%=rs.getObject(4) %></td> <td width=2% align="center"><%=rs.getObject(5) %></td> <td width=3% align="center"><%=rs.getObject(6) %></td> </tr> <% } } rs.close(); connect.close(); stmt.close(); }catch (SQLException e) { e.printStackTrace(); } %> </table> </body> <form id="1" action ="teacher-reviseback.jsp" method="get"> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br> 姓名: <input type="text" name="name"size="15"/> <br><br> 性别: <input type="text" name="sex"size="15"/> <br><br> 学院: <input type="text" name="yuan"size="15"/> <br><br> 职称: <select size ="1"name="zhichen"> <option value ="教授" selected>教授</option> <option value ="副教授">副教授</option> <option value ="讲师" >讲师</option> <option value ="助教" >助教</option> </select> <br><br> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> <br><br> <input type="submit" value="修改"/> <input type="reset" value="重置"/> </p> </form> </html>
teacher-reviseback.jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>修改信息</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String calss=session.getAttribute("calss").toString(); String num=session.getAttribute("num").toString(); String name=(String)request.getParameter("name"); String sex=(String)request.getParameter("sex"); String yuan=(String)request.getParameter("yuan"); String zhichen=(String)request.getParameter("zhichen"); String num1=num; if(util.queryTeacherxiu(name, sex, yuan, zhichen)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else{ util.teacherXiugai(calss, num, name, sex, yuan, zhichen, num1); out.print("<script language='javaScript'> alert('修改成功');</script>"); response.setHeader("refresh", "0;url=teacher.jsp"); } %> </body> </html>
teacher-watch.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>修改</title> </head> <body> <table border="1"style="text-align:center"> <caption>学生选课情况</caption> <tr> <td align="center" width=3%>课程编号</td> <td align="center" width=3%>课程名称</td> <td align="center" width=3%>学生学号</td> <td align="center" width=2%>学生姓名</td> <td align="center" width=2%>学生性别</td> <td align="center" width=3%>班级</td> <td align="center" width=3%>专业</td> </tr> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String num=session.getAttribute("num").toString(); try{ Connection connect = util.sjk(); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from xuanke"); while(rs.next()){ if(num.equals(rs.getObject(2).toString())) { %> <tr> <td width=3% align="center"><%=rs.getObject(1) %></td> <td width=3% align="center"><%=rs.getObject(3) %></td> <td width=3% align="center"><%=rs.getObject(6) %></td> <td width=2% align="center"><%=rs.getObject(7) %></td> <td width=2% align="center"><%=rs.getObject(8) %></td> <td width=3% align="center"><%=rs.getObject(9) %></td> <td width=3% align="center"><%=rs.getObject(10) %></td> </tr> <% } } rs.close(); connect.close(); stmt.close(); }catch (SQLException e) { e.printStackTrace(); } %> </table> <p style="text-align:center"> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> </p> </body> </html>
Txiu.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>修改</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <form id="1" action ="Txiuback.jsp" method="get"> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br> 输入旧密码: <input type="text" name="jiu"size="15"/> <br><br> 输入新密码: <input type="text" name="xin"size="15"/> <br><br> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> <br><br> <input type="submit" value="修改"/> <input type="reset" value="重置"/> </p> </form> </body> </html>
Txiuback.jsp
<%@page import="aD.Ac"%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>处理</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String calss="教师"; String num=session.getAttribute("num").toString(); String pass=session.getAttribute("pass").toString(); String jiu=(String)request.getParameter("jiu"); String xin=(String)request.getParameter("xin"); if(util.queryEmpty(jiu, xin)){ out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>"); }else if(!pass.equals(jiu)){ out.print("<script language ='javaScript'> alert('旧密码错误');window.history.back(-1); </script>"); }else if(util.numCha(xin)){ out.print("<script language ='javaScript'> alert('新密码必须为8位,且必须是数字');window.history.back(-1); </script>"); }else{ util.XiuM(xin, num,calss); out.print("<script language='javaScript'> alert('修改成功');</script>"); response.setHeader("refresh", "0;url=teacher.jsp"); } %> </body> </html>
xuanke.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>浏览</title> </head> <body> <table border="1"style="text-align:center"> <caption>课程信息</caption> <tr> <td align="center" width=3%>课程编号</td> <td align="center" width=3%>课程名字</td> <td align="center" width=3%>课程详细信息</td> <td align="center" width=3%>教师</td> </tr> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% try{ Connection connect = util.sjk(); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from classim"); while(rs.next()){ String a=rs.getObject(3).toString(); String b=rs.getObject(5).toString(); if(!a.equals(b)) { %> <tr> <td width=3% align="center"><%=rs.getObject(1) %></td> <td width=3% align="center"><%=rs.getObject(2) %></td> <td width=3% align="center"><a style="color:blue" href='xuanke-back.jsp?id=<%=rs.getObject(1) %>'>课程详细信息</a></td> <td width=3% align="center"><%=rs.getObject(4) %></td> </tr> <% } } rs.close(); connect.close(); stmt.close(); }catch (SQLException e) { e.printStackTrace(); } %> </table> </body> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> </p> </html>
xuanke-back.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>选课</title> </head> <body> <table border="1"style="text-align:center"> <caption>课程信息</caption> <tr> <td align="center" width=2%>课程编号</td> <td align="center" width=3%>课程名称</td> <td align="center" width=2%>任课老师</td> <td align="center" width=2%>已选人数</td> <td align="center" width=3%>人数上限</td> <td align="center" width=3%>选课</td> </tr> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String a=request.getParameter("id"); try{ Connection connect = util.sjk(); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from classim"); while(rs.next()){ if(a.equals(rs.getObject(1).toString())) { String classteachernum=rs.getObject(6).toString(); session.setAttribute("classteachernum", classteachernum); String classname=rs.getObject(2).toString(); session.setAttribute("classname", classname); String classmax=rs.getObject(3).toString(); session.setAttribute("classmax", classmax); String classteacher=rs.getObject(4).toString(); session.setAttribute("classteacher", classteacher); String classnow=rs.getObject(5).toString(); session.setAttribute("classnow", classnow); %> <tr> <td width=2% align="center"><%=rs.getObject(1) %></td> <td width=3% align="center"><%=rs.getObject(2) %></td> <td width=2% align="center"><%=rs.getObject(4) %></td> <td width=2% align="center"><%=rs.getObject(5) %></td> <td width=3% align="center"><%=rs.getObject(3) %></td> <td width=3% align="center"><a style="color:blue" href='xuanke-backback.jsp?classnum=<%=rs.getObject(1) %>'>选课</a></td> </tr> <% } } rs.close(); connect.close(); stmt.close(); }catch (SQLException e) { e.printStackTrace(); } %> </table> </body> <p style="text-align:center;color:black;font-family:楷体; font-size:20px"> <br><br> <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> </p> </html>
xuanke-backback.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>选课</title> </head> <body> <jsp:useBean id="util" class="aD.Ac" scope="page" /> <% String ak=session.getAttribute("num").toString(); String classnum=request.getParameter("classnum"); String classteachernum=session.getAttribute("classteachernum").toString(); String classname=session.getAttribute("classname").toString(); String classmax=session.getAttribute("classmax").toString(); String classteacher=session.getAttribute("classteacher").toString(); String classnow=session.getAttribute("classnow").toString(); String studentnum=null; String name=null; String sex=null; String banji=null; String zhuanye=null; try{ Connection connect = util.sjk(); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from student"); while(rs.next()){ if(ak.equals(rs.getObject(2).toString())) { studentnum=rs.getObject(2).toString(); name=rs.getObject(3).toString(); sex=rs.getObject(4).toString(); banji=rs.getObject(5).toString(); zhuanye=rs.getObject(6).toString(); } } rs.close(); connect.close(); stmt.close(); }catch (SQLException e) { e.printStackTrace(); } if(util.xuanchong(studentnum, classnum)) { out.print("<script language ='javaScript'> alert('你已经选过改课程');window.history.back(-1); </script>"); }else{ util.Xiugai(classnum, classnow); util.SinputClassT(classnum, classteachernum, classname, classmax, classteacher, studentnum, name, sex, banji, zhuanye); out.print("<script language='javaScript'> alert('选课成功');</script>"); response.setHeader("refresh", "0;url=student.jsp"); } %> </body> </html>
package aD; import java.sql.*; public class Ac { public Connection sjk() { Connection connect; try { connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); return connect; }catch(Exception e) { e.printStackTrace(); } return null; } public boolean inquiryNumber(String num,String calss) { boolean flag=true; try { Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from denglv"); while(rs.next()) { if(num.equals(rs.getString("num"))&&calss.equals(rs.getString("calss"))) { flag=false; } } rs.close(); stmt.close(); connect.close(); }catch (SQLException e) { e.printStackTrace(); } return flag; } public boolean pin(String max) { boolean flag=true; try { double a=Integer.valueOf(max); if(a>0&&a%1==0) flag=false; return flag; } catch (Exception e) { return flag; } } public boolean denlv(String calss,String num,String pass) { boolean flag=true; try { Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from denglv"); while(rs.next()) { if(num.equals(rs.getString("num"))&&calss.equals(rs.getString("calss"))&&pass.equals(rs.getString("pass"))) { flag=false; } } rs.close(); stmt.close(); connect.close(); }catch (SQLException e) { e.printStackTrace(); } return flag; } public String namereturn(String calss,String num) { String name=null; try { Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from teacher"); while(rs.next()) { if(num.equals(rs.getString("num"))&&calss.equals(rs.getString("calss"))) { name=rs.getString("name"); } } rs.close(); stmt.close(); connect.close(); }catch (SQLException e) { e.printStackTrace(); } return name; } public boolean classxichong(String classname,String classteacher) { boolean flag=false; try { Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from classim"); while(rs.next()) { if(classname.equals(rs.getString("classname"))&&classteacher.equals(rs.getString("classteacher"))) { flag=true; } } rs.close(); stmt.close(); connect.close(); }catch (SQLException e) { e.printStackTrace(); } return flag; } public boolean classnumchong(String classnumber) { boolean flag=false; try { Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from classim"); while(rs.next()) { if(classnumber.equals(rs.getString("classnum"))) { flag=true; } } rs.close(); stmt.close(); connect.close(); }catch (SQLException e) { e.printStackTrace(); } return flag; } public boolean addTeacherNum(String num) { boolean flag=false; try { Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from teacher"); while(rs.next()) { if(num.equals(rs.getString("num"))) { flag=true; } } rs.close(); stmt.close(); connect.close(); }catch (SQLException e) { e.printStackTrace(); } return flag; } public boolean addStudentNum(String num) { boolean flag=false; try { Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from student"); while(rs.next()) { if(num.equals(rs.getString("num"))) { flag=true; } } rs.close(); stmt.close(); connect.close(); }catch (SQLException e) { e.printStackTrace(); } return flag; } public boolean classnumCha(String num) { boolean flag=true; if(num.length()==6) { for(int i=0;i<num.length();i++) { char k=num.charAt(i); if(k=='0'||k=='1'||k=='2'||k=='3'||k=='4'||k=='5'||k=='6'||k=='7'||k=='8'||k=='9') continue; else return flag; } flag=false; } return flag; } public boolean numCha(String num) { boolean flag=true; if(num.length()==8) { for(int i=0;i<num.length();i++) { char k=num.charAt(i); if(k=='0'||k=='1'||k=='2'||k=='3'||k=='4'||k=='5'||k=='6'||k=='7'||k=='8'||k=='9') continue; else return flag; } flag=false; } return flag; } public boolean query(String num)//查空 { boolean flag=false; if(num==null||"".equals((num))) { flag=true; } return flag; } public boolean queryEmpty(String number,String password)//查空 { boolean flag=false; if(number==null||"".equals((number))&&password==null||"".equals(password)) { flag=true; } return flag; } public boolean queryTeacherAdd(String classnumber, String classname,String classmax)//查空 { boolean flag=false; if(classnumber==null||"".equals((classnumber))&&classname==null||"".equals(classname)&&classmax==null||"".equals(classmax)) { flag=true; } return flag; } public boolean queryTeacherxiu(String name,String sex,String yuan,String zhichen)//查空 { boolean flag=false; if(name==null||"".equals((name))&&sex==null||"".equals(sex)&&yuan==null||"".equals(yuan)&&zhichen==null||"".equals(zhichen)) { flag=true; } return flag; } public void teacherXiugai(String calss,String num,String name,String sex,String yuan,String zhichen,String num1) { try { PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("Update teacher set calss=?,num=?,name=?,sex=?,yuan=?,zhichen=? where num=?"); preparedStatement.setString(1,calss); preparedStatement.setString(2,num); preparedStatement.setString(3,name); preparedStatement.setString(4,sex); preparedStatement.setString(5,yuan); preparedStatement.setString(6,zhichen); preparedStatement.setString(7,num1); preparedStatement.executeUpdate(); preparedStatement.execute(); connect.close(); }catch(SQLException e){ e.printStackTrace(); } } public void Xiugai(String classnum,String classnow) { try { int a=Integer.valueOf(classnow); a++; String ac=String.valueOf(a); PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("Update classim set classnow=?where classnum=?"); preparedStatement.setString(1,ac); preparedStatement.setString(2,classnum); preparedStatement.executeUpdate(); preparedStatement.execute(); connect.close(); }catch(SQLException e){ e.printStackTrace(); } } public void studentXiugai(String calss,String num,String name,String sex,String yuan,String zhichen,String num1) { try { PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("Update student set calss=?,num=?,name=?,sex=?,banji=?,zhuanye=? where num=?"); preparedStatement.setString(1,calss); preparedStatement.setString(2,num); preparedStatement.setString(3,name); preparedStatement.setString(4,sex); preparedStatement.setString(5,yuan); preparedStatement.setString(6,zhichen); preparedStatement.setString(7,num1); preparedStatement.executeUpdate(); preparedStatement.execute(); connect.close(); }catch(SQLException e){ e.printStackTrace(); } } public void XiuM(String pass,String num,String calss) { try { PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("Update denglv set pass=? where num=? and calss=? "); preparedStatement.setString(1,pass); preparedStatement.setString(2,num); preparedStatement.setString(3,calss); preparedStatement.executeUpdate(); preparedStatement.execute(); connect.close(); }catch(SQLException e){ e.printStackTrace(); } } public void addTeaher(String calss,String num,String name,String sex,String yuan,String zhichen) { try { PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("insert into teacher (calss,num,name,sex,yuan,zhichen) values (?,?,?,?,?,?)"); preparedStatement.setString(1,calss); preparedStatement.setString(2,num); preparedStatement.setString(3,name); preparedStatement.setString(4,sex); preparedStatement.setString(5,yuan); preparedStatement.setString(6,zhichen); preparedStatement.executeUpdate(); connect.close(); preparedStatement.close(); }catch(SQLException e){ e.printStackTrace(); } try { PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("insert into denglv (calss,num,pass) values (?,?,?)"); preparedStatement.setString(1,calss); preparedStatement.setString(2,num); preparedStatement.setString(3,num); preparedStatement.executeUpdate(); connect.close(); preparedStatement.close(); }catch(SQLException e){ e.printStackTrace(); } } public void addStudent(String calss,String num,String name,String sex,String banji,String zhuanye) { try { PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("insert into student (calss,num,name,sex,banji,zhuanye) values (?,?,?,?,?,?)"); preparedStatement.setString(1,calss); preparedStatement.setString(2,num); preparedStatement.setString(3,name); preparedStatement.setString(4,sex); preparedStatement.setString(5,banji); preparedStatement.setString(6,zhuanye); preparedStatement.executeUpdate(); connect.close(); preparedStatement.close(); }catch(SQLException e){ e.printStackTrace(); } try { PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("insert into denglv (calss,num,pass) values (?,?,?)"); preparedStatement.setString(1,calss); preparedStatement.setString(2,num); preparedStatement.setString(3,num); preparedStatement.executeUpdate(); connect.close(); preparedStatement.close(); }catch(SQLException e){ e.printStackTrace(); } } public void inputClassT(String classnum,String classname,String classmax,String classteacher,String classnow,String teachernum) { try { PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("insert into classim (classnum,classname,classmax,classteacher,classnow,teachernum) values (?,?,?,?,?,?)"); preparedStatement.setString(1,classnum); preparedStatement.setString(2,classname); preparedStatement.setString(3,classmax); preparedStatement.setString(4,classteacher); preparedStatement.setString(5,classnow); preparedStatement.setString(6,teachernum); preparedStatement.executeUpdate(); connect.close(); preparedStatement.close(); }catch(SQLException e){ e.printStackTrace(); } } public void SinputClassT(String classnum,String classteachernum,String classname,String classmax,String classteacher,String studentnum,String name,String sex,String banji,String zhuanye) { try { PreparedStatement preparedStatement=null; Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); preparedStatement=connect.prepareStatement("insert into xuanke (classnum,classteachernum,classname,classmax,classteacher,stuentnum,name,sex,banji,zhuanye) values (?,?,?,?,?,?,?,?,?,?)"); preparedStatement.setString(1,classnum); preparedStatement.setString(2,classteachernum); preparedStatement.setString(3,classname); preparedStatement.setString(4,classmax); preparedStatement.setString(5,classteacher); preparedStatement.setString(6,studentnum); preparedStatement.setString(7,name); preparedStatement.setString(8,sex); preparedStatement.setString(9,banji); preparedStatement.setString(10,zhuanye); preparedStatement.executeUpdate(); connect.close(); preparedStatement.close(); }catch(SQLException e){ e.printStackTrace(); } } public boolean xuanchong(String studentnum,String classnum) { boolean flag=false; try { Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC","root","123456"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from xuanke"); while(rs.next()) { if(studentnum.equals(rs.getString("stuentnum"))&&classnum.equals(rs.getString("classnum"))) { flag=true; } } rs.close(); stmt.close(); connect.close(); }catch (SQLException e) { e.printStackTrace(); } return flag; } public static void main(String[] args) { Ac a=new Ac(); } }