该系统管理员可以添加和删除学生、教师,教师可以修改自己信息、添加课程、浏览自己课程,学生可以修改自己的信息、选课、浏览全部课程。
首先展示文件:
然后就是一次展示代码:
Guanli包中代码:
package Guanli; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import Login.DBUtil; public classAdd { publicboolean add(String table,AddService en) { boolean c=false; String sql="insert into "+table+"(username,password,power,name) values('"+en.getUsername()+"','"+en.getPassword()+"','"+en.getPower()+"','"+en.getName()+"');"; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); int num=state.executeUpdate(sql); if(num!=0) c=true; state.close(); conn.close(); } catch(SQLException e) { //TODO Auto-generated catch block //e.printStackTrace(); } returnc; } publicboolean add(String table,TeacherService en) { boolean c=false; String sql="insert into "+table+"(gonghao,xingming,xingbie,xueyuan,zhicheng) values('"+en.getGonghao()+"','"+en.getXingming()+"','"+en.getXingbie()+"','"+en.getXueyuan()+"','"+en.getZhicheng()+"');"; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); int num=state.executeUpdate(sql); if(num!=0) c=true; state.close(); conn.close(); } catch(SQLException e) { //TODO Auto-generated catch block //e.printStackTrace(); } returnc; } publicboolean add(String table,StudentService en) { boolean c=false; String sql="insert into "+table+"(xuehao,xingming,xingbie,banji,zhuanye) values('"+en.getXuehao()+"','"+en.getXingming()+"','"+en.getXingbie()+"','"+en.getBanji()+"','"+en.getZhuanye()+"');"; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); int num=state.executeUpdate(sql); if(num!=0) c=true; state.close(); conn.close(); } catch(SQLException e) { //TODO Auto-generated catch block //e.printStackTrace(); } returnc; } }
package Guanli; import java.sql.Time; import java.text.SimpleDateFormat; import java.util.Date; public classAddService { String username; String password; String name; publicString getName() { returnname; } public voidsetName(String name) { this.name =name; } intpower; publicString getUsername() { returnusername; } public voidsetUsername(String username) { this.username =username; } publicString getPassword() { returnpassword; } public voidsetPassword(String password) { this.password =password; } public intgetPower() { returnpower; } public void setPower(intpower) { this.power =power; } }
packageGuanli; importjava.awt.Desktop.Action; importjava.io.IOException; importjavax.servlet.ServletException; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importLogin.Power; importLogin.Select; /*** Servlet implementation class RegisterServlet */@WebServlet("/RegisterServlet") public class RegisterServlet extendsHttpServlet { private static final long serialVersionUID = 1L; /*** @seeHttpServlet#HttpServlet() */ publicRegisterServlet() { super(); //TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException { Select s=newSelect(); arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); booleanflag; String function=arg0.getParameter("method"); if(function.equals("teacher")) { AddService as=newAddService(); Add a=newAdd(); String username; username=arg0.getParameter("username"); as.setUsername(username); String password; password=arg0.getParameter("password"); as.setPassword(password); int num=1; as.setPower(num); TeacherService ts=newTeacherService(); String gonghao; gonghao=arg0.getParameter("gonghao"); ts.setGonghao(gonghao); String xingming; xingming=arg0.getParameter("xingming"); ts.setXingming(xingming); as.setName(xingming); String xingbie; xingbie=arg0.getParameter("xingbie"); ts.setXingbie(xingbie); String xueyuan; xueyuan=arg0.getParameter("xueyuan"); ts.setXueyuan(xueyuan); String zhicheng; zhicheng=arg0.getParameter("zhicheng"); ts.setZhicheng(zhicheng); a.add("login", as); a.add("teacher", ts); arg0.setAttribute("message","添加成功"); arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1); } if(function.equals("student")) { AddService as=newAddService(); Add a=newAdd(); String username; username=arg0.getParameter("username"); as.setUsername(username); String password; password=arg0.getParameter("password"); as.setPassword(password); int num=2; as.setPower(num); StudentService ss=newStudentService(); String xuehao; xuehao=arg0.getParameter("xuehao"); ss.setXuehao(xuehao); String xingming; xingming=arg0.getParameter("xingming"); ss.setXingming(xingming); as.setName(xingming); String xingbie; xingbie=arg0.getParameter("xingbie"); ss.setXingbie(xingbie); String banji; banji=arg0.getParameter("banji"); ss.setBanji(banji); String zhuanye; zhuanye=arg0.getParameter("zhuanye"); ss.setZhuanye(zhuanye); a.add("student", ss); a.add("login", as); arg0.setAttribute("message","添加成功"); arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1); } } /*** @seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /*** @seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub doGet(request, response); } }
packageGuanli; public classStudentService { String xuehao; String xingming; String xingbie; String banji; String zhuanye; publicString getXuehao() { returnxuehao; } public voidsetXuehao(String xuehao) { this.xuehao =xuehao; } publicString getXingming() { returnxingming; } public voidsetXingming(String xingming) { this.xingming =xingming; } publicString getXingbie() { returnxingbie; } public voidsetXingbie(String xingbie) { this.xingbie =xingbie; } publicString getBanji() { returnbanji; } public voidsetBanji(String banji) { this.banji =banji; } publicString getZhuanye() { returnzhuanye; } public voidsetZhuanye(String zhuanye) { this.zhuanye =zhuanye; } }
packageGuanli; public classTeacherService { String gonghao; String xingming; String xingbie; String xueyuan; String zhicheng; publicString getGonghao() { returngonghao; } public voidsetGonghao(String gonghao) { this.gonghao =gonghao; } publicString getXingming() { returnxingming; } public voidsetXingming(String xingming) { this.xingming =xingming; } publicString getXingbie() { returnxingbie; } public voidsetXingbie(String xingbie) { this.xingbie =xingbie; } publicString getXueyuan() { returnxueyuan; } public voidsetXueyuan(String xueyuan) { this.xueyuan =xueyuan; } publicString getZhicheng() { returnzhicheng; } public voidsetZhicheng(String zhicheng) { this.zhicheng =zhicheng; } }
Login包里的文件:
packageLogin; importjava.sql.Connection; importjava.sql.DriverManager; importjava.sql.PreparedStatement; importjava.sql.ResultSet; importjava.sql.SQLException; importjava.sql.Statement; /*** 数据库连接工具 * @authorHu * */ public classDBUtil { public static String db_url = "jdbc:mysql://localhost:3306/jianmintest?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8"; public static String db_user = "root"; public static String db_pass = "20183629"; public staticConnection getConn () { Connection conn = null; try{ Class.forName("com.mysql.jdbc.Driver");//加载驱动 conn =DriverManager.getConnection(db_url, db_user, db_pass); } catch(Exception e) { e.printStackTrace(); } returnconn; } /*** 关闭连接 * @paramstate * @paramconn */ public static voidclose (Statement state, Connection conn) { if (state != null) { try{ state.close(); } catch(SQLException e) { e.printStackTrace(); } } if (conn != null) { try{ conn.close(); } catch(SQLException e) { e.printStackTrace(); } } } public static voidclose (ResultSet rs, Statement state, Connection conn) { if (rs != null) { try{ rs.close(); } catch(SQLException e) { e.printStackTrace(); } } if (state != null) { try{ state.close(); } catch(SQLException e) { e.printStackTrace(); } } if (conn != null) { try{ conn.close(); } catch(SQLException e) { e.printStackTrace(); } } } public static void main(String[] args) throwsSQLException { Connection conn =getConn(); PreparedStatement pstmt = null; ResultSet rs = null; String sql ="select * from course"; pstmt =conn.prepareStatement(sql); rs =pstmt.executeQuery(); if(rs.next()){ System.out.println("空"); }else{ System.out.println("不空"); } } }
packageLogin; importjava.io.IOException; importjavax.servlet.ServletException; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; /*** Servlet implementation class LoginServlet */@WebServlet("/LoginServlet") public class LoginServlet extendsHttpServlet { private static final long serialVersionUID = 1L; /*** @seeHttpServlet#HttpServlet() */ publicLoginServlet() { super(); //TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException { Select s=newSelect(); arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); booleanflag; String function=arg0.getParameter("method"); if(function.equals("login")) { String username; username=arg0.getParameter("username"); String password; password=arg0.getParameter("password"); String power; power=arg0.getParameter("power"); int num=Integer.parseInt(power); flag=s.select("login", username, password,num); Power.setFlag(num); if(flag) { arg0.setAttribute("message","登录成功"); arg0.getRequestDispatcher("Home.jsp").forward(arg0, arg1); } else{ arg0.setAttribute("message", "账号或密码有误"); arg0.getRequestDispatcher("Login.jsp").forward(arg0, arg1); } } } /*** @seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /*** @seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub doGet(request, response); } }
packageLogin; public classPower { static intflag; public static intgetFlag() { returnflag; } public static void setFlag(intflag) { Power.flag =flag; } staticString xingming; public staticString getXingming() { returnxingming; } public static voidsetXingming(String xingming) { Power.xingming =xingming; } staticString username; public staticString getUsername() { returnusername; } public static voidsetUsername(String username) { Power.username =username; } }
packageLogin; importjava.sql.Connection; importjava.sql.ResultSet; importjava.sql.SQLException; importjava.sql.Statement; public classSelect { public boolean select(String table,String username,String password,intnum) { boolean f=false; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); String sql="select * from "+table; ResultSet rs=state.executeQuery(sql); while(rs.next()) { if(username.equals(rs.getString(1))&&password.equals(rs.getString(2))&&rs.getInt(4)==num) { Power.setXingming(rs.getString(3)); Power.setUsername(rs.getString(1)); System.out.println(Power.getXingming()); f=true; } } rs.close(); state.close(); conn.close(); } catch(Exception e) { } returnf; } }
Student包中的代码:
packageStudent; importjava.sql.Connection; importjava.sql.SQLException; importjava.sql.Statement; importLogin.DBUtil; public classAdd { public booleanadd(String table,Jieguo en) { boolean c=false; String sql="insert into "+table+"(kechengbianhao,gonghao,jiaoshixingming,xuehao,xingming) values('"+en.getKechengbianhao()+"','"+en.getGonghao()+"','"+en.getJiaoshixingming()+"','"+en.getXuehao()+"','"+en.getXingming()+"');"; System.out.println(sql); Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); int num=state.executeUpdate(sql); if(num!=0) c=true; state.close(); conn.close(); } catch(SQLException e) { //TODO Auto-generated catch block //e.printStackTrace(); } returnc; } }
packageStudent; importjava.sql.Connection; importjava.sql.SQLException; importjava.sql.Statement; importLogin.DBUtil; public classChange { public booleanchange(String table,String lie,String lie0,String gai,String biao) { Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); String sql="update "+table+" set "+lie+"='"+gai+"' where "+lie0+"='"+biao+"'"; System.out.println(sql); state.executeUpdate(sql); state.close(); conn.close(); } catch(SQLException e) { //TODO Auto-generated catch block e.printStackTrace(); } return true; } }
packageStudent; importjava.sql.Connection; importjava.sql.ResultSet; importjava.sql.Statement; importLogin.DBUtil; public classFind { public booleanfind(String table,String id) { booleanc; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); String sql="select * from "+table+" where xingming ='"+id+"'"; ResultSet rs=state.executeQuery(sql); while(rs.next()) { Service.setXuehao(rs.getString(1)); Service.setXingming(rs.getString(2)); Service.setXingbie(rs.getString(3)); Service.setBanji(rs.getString(4)); Service.setZhuanye(rs.getString(5)); } rs.close(); state.close(); conn.close(); System.out.println("over"); } catch(Exception e) { } return true; } public voidfindclass(String table,String id) { booleanc; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); String sql="select * from "+table+" where kechengbianhao ='"+id+"'"; ResultSet rs=state.executeQuery(sql); while(rs.next()) { KechengService.setKechengbianhao(rs.getString(1)); KechengService.setKechengmingcheng(rs.getString(2)); KechengService.setRenkejiaoshi(rs.getString(4)); KechengService.setRenshushangxian(rs.getInt(5)); KechengService.setXianyourenshu(rs.getInt(6)); } rs.close(); state.close(); conn.close(); System.out.println("over"); } catch(Exception e) { } } public voidfindjiaoshi(String table,String id) { booleanc; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); String sql="select * from "+table+" where gonghao ='"+id+"'"; ResultSet rs=state.executeQuery(sql); while(rs.next()) { TeacherService.setGonghao(rs.getString(1)); TeacherService.setXingming(rs.getString(2)); TeacherService.setXingbie(rs.getString(3)); TeacherService.setXueyuan(rs.getString(4)); TeacherService.setZhicheng(rs.getString(5)); } rs.close(); state.close(); conn.close(); System.out.println("over"); } catch(Exception e) { } } }
packageStudent; importjava.sql.Connection; importjava.sql.PreparedStatement; importjava.sql.ResultSet; importjava.util.ArrayList; importjava.util.List; importLogin.DBUtil; importTeacher.KechengService; public classGet { public static List<KechengService>getAll() { List<KechengService> list=new ArrayList<KechengService>(); Connection conn=DBUtil.getConn(); PreparedStatement state=null; ResultSet rs=null; String sql="select * from class"; try{ state=conn.prepareStatement(sql); rs=state.executeQuery(); while(rs.next()) { if(rs.getInt(5)>rs.getInt(6)) { KechengService user=newKechengService(); user.setKechengbianhao(rs.getString(1)); user.setKechengmingcheng(rs.getString(2)); user.setGonghao(rs.getString(3)); user.setRenkejiaoshi(rs.getString(4)); user.setXianyourenshu(rs.getInt(6)); list.add(user); } } rs.close(); state.close(); conn.close(); } catch(Exception e) { } if(list!=null) { returnlist; }else{ return null; } } public static List<KechengService>getAll0() { List<KechengService> list=new ArrayList<KechengService>(); Connection conn=DBUtil.getConn(); PreparedStatement state=null; ResultSet rs=null; String sql="select * from class"; try{ state=conn.prepareStatement(sql); rs=state.executeQuery(); while(rs.next()) { KechengService user=newKechengService(); user.setKechengbianhao(rs.getString(1)); user.setKechengmingcheng(rs.getString(2)); user.setGonghao(rs.getString(3)); user.setRenkejiaoshi(rs.getString(4)); user.setXianyourenshu(rs.getInt(6)); list.add(user); } rs.close(); state.close(); conn.close(); } catch(Exception e) { } if(list!=null) { returnlist; }else{ return null; } } }
packageStudent; public classJieguo { String kechengbianhao; String jiaoshixingming; String gonghao; String xuehao; String xingming; publicString getGonghao() { returngonghao; } public voidsetGonghao(String gonghao) { this.gonghao =gonghao; } publicString getKechengbianhao() { returnkechengbianhao; } public voidsetKechengbianhao(String kechengbianhao) { this.kechengbianhao =kechengbianhao; } publicString getJiaoshixingming() { returnjiaoshixingming; } public voidsetJiaoshixingming(String jiaoshixingming) { this.jiaoshixingming =jiaoshixingming; } publicString getXuehao() { returnxuehao; } public voidsetXuehao(String xuehao) { this.xuehao =xuehao; } publicString getXingming() { returnxingming; } public voidsetXingming(String xingming) { this.xingming =xingming; } }
packageStudent; public classKechengService { staticString kechengbianhao; staticString kechengmingcheng; staticString renkejiaoshi; static intxianyourenshu; static intrenshushangxian; public static intgetRenshushangxian() { returnrenshushangxian; } public static void setRenshushangxian(intrenshushangxian) { KechengService.renshushangxian =renshushangxian; } public staticString getKechengbianhao() { returnkechengbianhao; } public static voidsetKechengbianhao(String kechengbianhao) { KechengService.kechengbianhao =kechengbianhao; } public staticString getKechengmingcheng() { returnkechengmingcheng; } public static voidsetKechengmingcheng(String kechengmingcheng) { KechengService.kechengmingcheng =kechengmingcheng; } public staticString getRenkejiaoshi() { returnrenkejiaoshi; } public static voidsetRenkejiaoshi(String renkejiaoshi) { KechengService.renkejiaoshi =renkejiaoshi; } public static intgetXianyourenshu() { returnxianyourenshu; } public static void setXianyourenshu(intxianyourenshu) { KechengService.xianyourenshu =xianyourenshu; } }
packageStudent; importjava.io.IOException; importjava.util.List; importjavax.servlet.ServletException; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importLogin.Power; importTeacher.KechengService; /*** Servlet implementation class LLKEServlet */@WebServlet("/LLKCServlet") public class LLKCServlet extendsHttpServlet { private static final long serialVersionUID = 1L; /*** @seeHttpServlet#HttpServlet() */ publicLLKCServlet() { super(); //TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException { arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); booleanflag; String function=arg0.getParameter("method"); if(function.equals("submit")) { List<KechengService> userall =Get.getAll0(); java.util.Collections.reverse(userall); arg0.setAttribute("all", userall); arg0.getRequestDispatcher("student/liulan.jsp").forward(arg0, arg1); } if(function.equals("kecheng")) { String kechengbianhao=arg0.getParameter("kechengbianhao"); Find f=newFind(); f.findclass("class", kechengbianhao); arg0.getRequestDispatcher("student/kecheng.jsp").forward(arg0, arg1); } if(function.equals("jiaoshi")) { String gonghao; gonghao=arg0.getParameter("gonghao"); Find f=newFind(); f.findjiaoshi("teacher", gonghao); arg0.getRequestDispatcher("student/jiaoshi.jsp").forward(arg0, arg1); } } /*** @seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /*** @seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub doGet(request, response); } }
packageStudent; importjava.sql.Connection; importjava.sql.ResultSet; importjava.sql.SQLException; importjava.sql.Statement; importLogin.DBUtil; public classSelect { public booleanselect(String table,String kechengbianhao,String xuehao) { boolean c=true; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); String sql="select * from "+table; ResultSet rs=state.executeQuery(sql); while(rs.next()) { if(kechengbianhao.equals(rs.getString(1))&&xuehao.equals(rs.getString(4))) { c=false; } } rs.close(); state.close(); conn.close(); } catch(Exception e) { } returnc; } }
packageStudent; public classService { staticString xuehao; staticString xingming; staticString xingbie; staticString banji; staticString zhuanye; public staticString getXuehao() { returnxuehao; } public static voidsetXuehao(String xuehao) { Service.xuehao =xuehao; } public staticString getXingming() { returnxingming; } public static voidsetXingming(String xingming) { Service.xingming =xingming; } public staticString getXingbie() { returnxingbie; } public static voidsetXingbie(String xingbie) { Service.xingbie =xingbie; } public staticString getBanji() { returnbanji; } public static voidsetBanji(String banji) { Service.banji =banji; } public staticString getZhuanye() { returnzhuanye; } public static voidsetZhuanye(String zhuanye) { Service.zhuanye =zhuanye; } }
packageStudent; importjava.io.IOException; importjavax.servlet.ServletException; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importLogin.Power; /*** Servlet implementation class SXiugaiServlet */@WebServlet("/SXiugaiServlet") public class SXiugaiServlet extendsHttpServlet { private static final long serialVersionUID = 1L; /*** @seeHttpServlet#HttpServlet() */ publicSXiugaiServlet() { super(); //TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException { arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); booleanflag; String function=arg0.getParameter("method"); if(function.equals("submit")) { Find f=newFind(); f.find("student", Power.getXingming()); arg0.getRequestDispatcher("student/xiugaixinxi.jsp").forward(arg0, arg1); } if(function.equals("xiugai")) { Change c=newChange(); String xingming; xingming=arg0.getParameter("xingming"); String xingbie; xingbie=arg0.getParameter("xingbie"); String banji; banji=arg0.getParameter("banji"); String zhuanye; zhuanye=arg0.getParameter("zhuanye"); c.change("jieguo", "xingming", "xuehao", xingming, Service.getXuehao()); c.change("login", "name", "username", xingming, Power.getUsername()); Power.setUsername(xingming); c.change("student", "xingming", "xuehao", xingming, Service.getXuehao()); c.change("student", "xingbie", "xuehao", xingbie, Service.getXuehao()); c.change("student", "xueyuan", "xuehao", banji, Service.getXuehao()); c.change("student", "zhicheng", "xuehao", zhuanye, Service.getXuehao()); arg0.setAttribute("message", "修改成功"); arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1); } } /*** @seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /*** @seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub doGet(request, response); } }
packageStudent; public classTeacherService { staticString gonghao; staticString xingming; staticString xingbie; staticString xueyuan; staticString zhicheng; public staticString getGonghao() { returngonghao; } public static voidsetGonghao(String gonghao) { TeacherService.gonghao =gonghao; } public staticString getXingming() { returnxingming; } public static voidsetXingming(String xingming) { TeacherService.xingming =xingming; } public staticString getXingbie() { returnxingbie; } public static voidsetXingbie(String xingbie) { TeacherService.xingbie =xingbie; } public staticString getXueyuan() { returnxueyuan; } public static voidsetXueyuan(String xueyuan) { TeacherService.xueyuan =xueyuan; } public staticString getZhicheng() { returnzhicheng; } public static voidsetZhicheng(String zhicheng) { TeacherService.zhicheng =zhicheng; } }
packageStudent; importjava.io.IOException; importjava.util.List; importjavax.servlet.ServletException; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importLogin.Power; importTeacher.KechengService; /*** Servlet implementation class XuankeServlet */@WebServlet("/XuankeServlet") public class XuankeServlet extendsHttpServlet { private static final long serialVersionUID = 1L; /*** @seeHttpServlet#HttpServlet() */ publicXuankeServlet() { super(); //TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException { arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); booleanflag; String function=arg0.getParameter("method"); if(function.equals("submit")) { List<KechengService> userall =Get.getAll(); java.util.Collections.reverse(userall); arg0.setAttribute("all", userall); arg0.getRequestDispatcher("student/xuanke.jsp").forward(arg0, arg1); } if(function.equals("xuanke")) { Change c=newChange(); Jieguo j=newJieguo(); Find f=newFind(); f.find("student", Power.getXingming()); String jiaoshixingming; jiaoshixingming=arg0.getParameter("jiaoshixingming"); j.setJiaoshixingming(jiaoshixingming); String kechengbianhao; kechengbianhao=arg0.getParameter("kechengbianhao"); j.setKechengbianhao(kechengbianhao); String xianyourenshu; xianyourenshu=arg0.getParameter("xianyourenshu"); String gonghao; gonghao=arg0.getParameter("gonghao"); j.setGonghao(gonghao); j.setXingming(Service.getXingming()); j.setXuehao(Service.getXuehao()); int num=Integer.parseInt(xianyourenshu); num++; System.out.println(num); Select s=newSelect(); flag=s.select("jieguo",kechengbianhao,Service.getXuehao()); if(flag) { c.change("class", "xianyourenshu", "kechengbianhao", num+"", kechengbianhao); Add a=newAdd(); a.add("jieguo", j); arg0.setAttribute("message", "选课成功"); arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1); } else{ arg0.setAttribute("message", "选课重复"); arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1); } } } /*** @seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /*** @seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub doGet(request, response); } }
Teacher包中的文件:
packageTeacher; importjava.sql.Connection; importjava.sql.SQLException; importjava.sql.Statement; importLogin.DBUtil; public classAdd { public booleanadd(String table,KechengService en) { boolean c=false; String sql="insert into "+table+"(kechengbianhao,kechengmingcheng,gonghao,renkejiaoshi,renshushangxian,xianyourenshu) values('"+en.getKechengbianhao()+"','"+en.getKechengmingcheng()+"','"+en.getGonghao()+"','"+en.getRenkejiaoshi()+"','"+en.getRenshushangxian()+"','"+en.getXianyourenshu()+"');"; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); int num=state.executeUpdate(sql); if(num!=0) c=true; state.close(); conn.close(); } catch(SQLException e) { //TODO Auto-generated catch block //e.printStackTrace(); } returnc; } }
packageTeacher; importjava.sql.Connection; importjava.sql.SQLException; importjava.sql.Statement; importLogin.DBUtil; public classChange { public booleanchange(String table,String lie,String lie0,String gai,String biao) { Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); String sql="update "+table+" set "+lie+"='"+gai+"' where "+lie0+"='"+biao+"'"; System.out.println(sql); state.executeUpdate(sql); state.close(); conn.close(); } catch(SQLException e) { //TODO Auto-generated catch block e.printStackTrace(); } return true; } }
packageTeacher; importjava.sql.Connection; importjava.sql.ResultSet; importjava.sql.Statement; importLogin.DBUtil; public classFind { public booleanfind(String table,String id) { booleanc; Connection conn=DBUtil.getConn(); Statement state=null; try{ state=conn.createStatement(); String sql="select * from "+table+" where xingming ='"+id+"'"; ResultSet rs=state.executeQuery(sql); while(rs.next()) { Service.setGonghao(rs.getString(1)); Service.setXingming(rs.getString(2)); Service.setXingbie(rs.getString(3)); Service.setXueyuan(rs.getString(4)); Service.setZhicheng(rs.getString(5)); } rs.close(); state.close(); conn.close(); System.out.println("over"); } catch(Exception e) { } return true; } }
packageTeacher; importjava.sql.Connection; importjava.sql.PreparedStatement; importjava.sql.ResultSet; importjava.util.ArrayList; importjava.util.List; importLogin.DBUtil; public classGet { public static List<KechengService>getAll(String id) { List<KechengService> list=new ArrayList<KechengService>(); Connection conn=DBUtil.getConn(); PreparedStatement state=null; ResultSet rs=null; String sql="select * from class where gonghao ='"+id+"'"; try{ state=conn.prepareStatement(sql); rs=state.executeQuery(); while(rs.next()) { KechengService user=newKechengService(); user.setKechengbianhao(rs.getString(1)); user.setKechengmingcheng(rs.getString(2)); user.setGonghao(rs.getString(3)); user.setRenkejiaoshi(rs.getString(4)); user.setXianyourenshu(rs.getInt(6)); list.add(user); } rs.close(); state.close(); conn.close(); } catch(Exception e) { } if(list!=null) { returnlist; }else{ return null; } } public static List<Xuesheng>getAllxs(String bianhao) { List<Xuesheng> list=new ArrayList<Xuesheng>(); Connection conn=DBUtil.getConn(); PreparedStatement state=null; ResultSet rs=null; String sql="select * from jieguo"; try{ state=conn.prepareStatement(sql); rs=state.executeQuery(); while(rs.next()) { if(rs.getString(1).equals(bianhao)) { Xuesheng user=newXuesheng(); user.setXingming(rs.getString(4)); user.setXuehao(rs.getString(3)); list.add(user); } } rs.close(); state.close(); conn.close(); } catch(Exception e) { } if(list!=null) { returnlist; }else{ return null; } } }
packageTeacher; public classKechengService { String kechengbianhao; String kechengmingcheng; String renkejiaoshi; intrenshushangxian; intxianyourenshu; String gonghao; publicString getGonghao() { returngonghao; } public voidsetGonghao(String gonghao) { this.gonghao =gonghao; } publicString getKechengbianhao() { returnkechengbianhao; } public voidsetKechengbianhao(String kechengbianhao) { this.kechengbianhao =kechengbianhao; } publicString getKechengmingcheng() { returnkechengmingcheng; } public voidsetKechengmingcheng(String kechengmingcheng) { this.kechengmingcheng =kechengmingcheng; } publicString getRenkejiaoshi() { returnrenkejiaoshi; } public voidsetRenkejiaoshi(String renkejiaoshi) { this.renkejiaoshi =renkejiaoshi; } public intgetRenshushangxian() { returnrenshushangxian; } public void setRenshushangxian(intrenshushangxian) { this.renshushangxian =renshushangxian; } public intgetXianyourenshu() { returnxianyourenshu; } public void setXianyourenshu(intxianyourenshu) { this.xianyourenshu =xianyourenshu; } }
packageTeacher; importjava.io.IOException; importjavax.servlet.ServletException; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importLogin.Power; importLogin.Select; /*** Servlet implementation class KechengServlet */@WebServlet("/KechengServlet") public class KechengServlet extendsHttpServlet { private static final long serialVersionUID = 1L; /*** @seeHttpServlet#HttpServlet() */ publicKechengServlet() { super(); //TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException { Select s=newSelect(); arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); booleanflag; String function=arg0.getParameter("method"); if(function.equals("submit")) { Find f=newFind(); f.find("teacher", Power.getXingming()); Add a=newAdd(); KechengService ks=newKechengService(); String kechengbianhao; kechengbianhao=arg0.getParameter("kechengbianhao"); ks.setKechengbianhao(kechengbianhao); String kechengmingcheng; kechengmingcheng=arg0.getParameter("kechengmingcheng"); ks.setKechengmingcheng(kechengmingcheng); String renkejiaoshi; renkejiaoshi=Power.getXingming(); String gonghao; gonghao=Service.getGonghao(); ks.setGonghao(gonghao); ks.setRenkejiaoshi(renkejiaoshi); String renshushangxian; renshushangxian=arg0.getParameter("renshushangxian"); int num=Integer.parseInt(renshushangxian); ks.setRenshushangxian(num); ks.setXianyourenshu(0); a.add("class", ks); arg0.setAttribute("message", "添加成功"); arg0.getRequestDispatcher("teacher/tianjiakecheng.jsp").forward(arg0, arg1); } } /*** @seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /*** @seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub doGet(request, response); } }
packageTeacher; importjava.io.IOException; importjava.util.List; importjavax.servlet.ServletException; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importLogin.Power; importLogin.Select; /*** Servlet implementation class LiulanServlet */@WebServlet("/LiulanServlet") public class LiulanServlet extendsHttpServlet { private static final long serialVersionUID = 1L; /*** @seeHttpServlet#HttpServlet() */ publicLiulanServlet() { super(); //TODO Auto-generated constructor stub } /*** @seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException { Select s=newSelect(); arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); booleanflag; String function=arg0.getParameter("method"); if(function.equals("liulan")) { List<KechengService> userall =Get.getAll(Service.getGonghao()); java.util.Collections.reverse(userall); arg0.setAttribute("all", userall); arg0.getRequestDispatcher("teacher/liulanxuanke.jsp").forward(arg0, arg1); } if(function.equals("xiangxi")) { String kechengbianhao; kechengbianhao=arg0.getParameter("kechengbianhao"); List<Xuesheng> userall =Get.getAllxs(kechengbianhao); java.util.Collections.reverse(userall); arg0.setAttribute("all", userall); arg0.getRequestDispatcher("teacher/xiangxi.jsp").forward(arg0, arg1); } } /*** @seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub doGet(request, response); } }
packageTeacher; public classService { staticString gonghao; staticString xingming; staticString xingbie; staticString xueyuan; public staticString getGonghao() { returngonghao; } public static voidsetGonghao(String gonghao) { Service.gonghao =gonghao; } public staticString getXingming() { returnxingming; } public static voidsetXingming(String xingming) { Service.xingming =xingming; } public staticString getXingbie() { returnxingbie; } public static voidsetXingbie(String xingbie) { Service.xingbie =xingbie; } public staticString getXueyuan() { returnxueyuan; } public static voidsetXueyuan(String xueyuan) { Service.xueyuan =xueyuan; } public staticString getZhicheng() { returnzhicheng; } public static voidsetZhicheng(String zhicheng) { Service.zhicheng =zhicheng; } staticString zhicheng; }
packageTeacher; importjava.io.IOException; importjavax.servlet.ServletException; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importLogin.Power; /*** Servlet implementation class TXiugaiServlet */@WebServlet("/TXiugaiServlet") public class TXiugaiServlet extendsHttpServlet { private static final long serialVersionUID = 1L; /*** @seeHttpServlet#HttpServlet() */ publicTXiugaiServlet() { super(); //TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException { arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); booleanflag; String function=arg0.getParameter("method"); if(function.equals("submit")) { Find f=newFind(); f.find("teacher", Power.getXingming()); arg0.getRequestDispatcher("teacher/xiugaixinxi.jsp").forward(arg0, arg1); } if(function.equals("xiugai")) { Change c=newChange(); String xingming; xingming=arg0.getParameter("xingming"); String xingbie; xingbie=arg0.getParameter("xingbie"); String xueyuan; xueyuan=arg0.getParameter("xueyuan"); String zhicheng; zhicheng=arg0.getParameter("zhicheng"); c.change("class", "renkejiaoshi", "gonghao", xingming, Service.getGonghao()); c.change("login", "name", "username", xingming, Power.getUsername()); Power.setUsername(xingming); c.change("teacher", "xingming", "gonghao", xingming, Service.getGonghao()); c.change("teacher", "xingbie", "gonghao", xingbie, Service.getGonghao()); c.change("teacher", "xueyuan", "gonghao", xueyuan, Service.getGonghao()); c.change("teacher", "zhicheng", "gonghao", zhicheng, Service.getGonghao()); arg0.setAttribute("message", "修改成功"); arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1); } } /*** @seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /*** @seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { //TODO Auto-generated method stub doGet(request, response); } }
packageTeacher; public classXuesheng { String xingming; String xuehao; publicString getXingming() { returnxingming; } public voidsetXingming(String xingming) { this.xingming =xingming; } publicString getXuehao() { returnxuehao; } public voidsetXuehao(String xuehao) { this.xuehao =xuehao; } }
JSP文件中:
guanli文件夹:
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Insert title here</title> </head> <% // //接收servlet传过来的那个message的参数 //alert是js语句中的弹出警示框,也就是弹出message中的参数 Object message=request.getAttribute("message"); if(!(message==null||message.equals(""))) { %> <script type="text/javascript">alert('<%=message%>')</script> <%} %> <body align="center"> <form action="${pageContext.request.contextPath}/RegisterServlet?method=teacher"method="post"> <table algin="center"> <tr> <td>账号</td> <td><input type="text"name="username"></td> </tr> <tr> <td>密码</td> <td><input type="password"name="password"></td> </tr> <tr> <td>工号:</td> <td><input type="text"name="gonghao"></td> </tr> <tr> <td>姓名:</td> <td><input type="text"name="xingming"></td> </tr> <tr> <td>性别:</td> <td><input type="text"name="xingbie"></td> </tr> <tr> <td>所在学院:</td> <td><input type="text"name="xueyuan"></td> </tr> <tr> <td>职称:</td> <td><input type="text"name="zhicheng"></td> </tr> </table> <p><input type="submit"value="确定添加"style="100px;height:30px;background-color:#bdd7f2;"></p> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Insert title here</title> </head> <% // //接收servlet传过来的那个message的参数 //alert是js语句中的弹出警示框,也就是弹出message中的参数 Object message=request.getAttribute("message"); if(!(message==null||message.equals(""))) { %> <script type="text/javascript">alert('<%=message%>')</script> <%} %> <body align="center"> <form action="${pageContext.request.contextPath}/RegisterServlet?method=student"method="post"> <table algin="center"> <tr> <td>账号</td> <td><input type="text"name="username"></td> </tr> <tr> <td>密码</td> <td><input type="password"name="password"></td> </tr> <tr> <td>学号:</td> <td><input type="text"name="xuehao"></td> </tr> <tr> <td>姓名:</td> <td><input type="text"name="xingming"></td> </tr> <tr> <td>性别:</td> <td><input type="text"name="xingbie"></td> </tr> <tr> <td>班级:</td> <td><input type="text"name="banji"></td> </tr> <tr> <td>专业:</td> <td><input type="text"name="zhuanye"></td> </tr> </table> <p><input type="submit"value="确定添加"style="100px;height:30px;background-color:#bdd7f2;"></p> </form> </body> </html>
student文件夹中:
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <%@ page language="java" import="Student.TeacherService"%> <title>Insert title here</title> </head> <body style="margin-top:100px"> <table align="center"> <tr> <td>工号:</td> <td><%=TeacherService.getGonghao() %></td> </tr> <tr> <td>任课教师</td> <td><%=TeacherService.getXingming() %></td> </tr> <tr> <td>教师性别</td> <td><%=TeacherService.getXingbie() %></td> </tr> <tr> <td>学院:</td> <td><%=TeacherService.getXueyuan() %></td> </tr> <tr> <td>职称</td> <td><%=TeacherService.getZhicheng() %></td> </tr> </table> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <%@ page language="java" import="Student.KechengService"%> <title>Insert title here</title> </head> <body style="margin-top:100px;"> <table align="center"> <tr> <td>课程编号:</td> <td><%=KechengService.getKechengbianhao()%></td> </tr> <tr> <td>课程名称:</td> <td><%=KechengService.getKechengmingcheng() %></td> </tr> <tr> <td>任课教师:</td> <td><%=KechengService.getRenkejiaoshi() %></td> </tr> <tr> <td>课程容量:</td> <td><%=KechengService.getRenshushangxian() %></td> </tr> <tr> <td>现有人数:</td> <td><%=KechengService.getXianyourenshu() %></td> </tr> </table> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<tr>
<td>课程名称</td>
<td>课程编号</td>
<td>任课教师</td>
</tr>
<c:forEach var="stu" items="${all}" >
<tr>
<td><a href="http://t.zoukankan.com/LLKCServlet?method=kecheng&kechengbianhao=${stu.getKechengmingcheng() }">${stu.getKechengmingcheng() }</a></td>
<td>${stu.getKechengbianhao() }</td>
<td><a href="http://t.zoukankan.com/LLKCServlet?method=jiaoshi&gonghao=${stu.getGonghao() }">${stu.getRenkejiaoshi() }</a></td>
</tr>
</c:forEach>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <%@ page language="java" import="Student.Service"%> <title>Insert title here</title> </head> <% // //接收servlet传过来的那个message的参数 //alert是js语句中的弹出警示框,也就是弹出message中的参数 Object message=request.getAttribute("message"); if(!(message==null||message.equals(""))) { %> <script type="text/javascript">alert('<%=message%>')</script> <%} %> <body> <form action="${pageContext.request.contextPath}/SXiugaiServlet?method=xiugai"method="post"> <table> <tr> <td>学号</td> <td><%=Service.getXuehao() %></td> </tr> <tr> <td>姓名</td> <td><input type="text"name="xingming"value=<%=Service.getXingming() %>></td> </tr> <tr> <td>性别</td> <td><input type="text"name="xingbie"value=<%=Service.getXingbie() %>></td> </tr> <tr> <td>班级</td> <td><input type="text"name="banji"value=<%=Service.getBanji() %>></td> </tr> <tr> <td>专业</td> <td><input type="text"name="zhuanye"value=<%=Service.getZhuanye() %>></td> </tr> </table> <p><input type="submit"value="确定添加"style="100px;height:30px;background-color:#bdd7f2;"></p> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<tr>
<td>课程名称</td>
<td>课程编号</td>
<td>任课教师</td>
<td>操作</td>
</tr>
<c:forEach var="stu" items="${all}" >
<tr>
<td>${stu.getKechengmingcheng() }</td>
<td>${stu.getKechengbianhao() }</td>
<td>${stu.getRenkejiaoshi() }</td>
<td><a href="http://t.zoukankan.com/${pageContext.request.contextPath}/XuankeServlet?method=xuanke&kechengbianhao=${stu.getKechengbianhao()}&xianyourenshu=${stu.getXianyourenshu()}&jiaoshixingming=${stu.getRenkejiaoshi()}&gonghao=${stu.getGonghao()}">选课</a></td>
</tr>
</c:forEach>
</table>
</body>
</html>
teacher文件中的:
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<tr>
<td>课程名称</td>
<td>课程编号</td>
<td>现有人数</td>
</tr>
<c:forEach var="stu" items="${all}" >
<tr>
<td><a href="http://t.zoukankan.com/${pageContext.request.contextPath}/LiulanServlet?method=xiangxi&kechengbianhao=${stu.getKechengbianhao()}&xianyourenshu=${stu.getXianyourenshu()}">${stu.getKechengmingcheng()}</a></td>
<td>${stu.getKechengbianhao() }</td>
<td>${stu.getXianyourenshu() }</td>
</tr>
</c:forEach>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Insert title here</title> </head> <% // //接收servlet传过来的那个message的参数 //alert是js语句中的弹出警示框,也就是弹出message中的参数 Object message=request.getAttribute("message"); if(!(message==null||message.equals(""))) { %> <script type="text/javascript">alert('<%=message%>')</script> <%} %> <body> <form action="${pageContext.request.contextPath}/KechengServlet?method=submit"method="post"> <table align="center"> <tr> <td>课程编号</td> <td><input type="text"name="kechengbianhao"></td> </tr> <tr> <td>课程名称</td> <td><input type="text"name="kechengmingcheng"></td> </tr> <tr> <td>课程人数</td> <td><input type="text"name="renshushangxian"></td> </tr> </table> <p><input type="submit"value="确定添加"style="100px;height:30px;background-color:#bdd7f2;"></p> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<tr>
<td>姓名</td>
<td>学号</td>
</tr>
<c:forEach var="stu" items="${all}" >
<tr>
<td>${stu.getXingming() }</td>
<td>${stu.getXuehao() }</td>
</tr>
</c:forEach>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <%@ page language="java" import="Teacher.Service"%> <title>Insert title here</title> </head> <% // //接收servlet传过来的那个message的参数 //alert是js语句中的弹出警示框,也就是弹出message中的参数 Object message=request.getAttribute("message"); if(!(message==null||message.equals(""))) { %> <script type="text/javascript">alert('<%=message%>')</script> <%} %> <body> <form action="${pageContext.request.contextPath}/TXiugaiServlet?method=xiugai"method="post"> <table> <tr> <td>工号</td> <td><%=Service.getGonghao() %></td> </tr> <tr> <td>姓名</td> <td><input type="text"name="xingming"value=<%=Service.getXingming() %>></td> </tr> <tr> <td>性别</td> <td><input type="text"name="xingbie"value=<%=Service.getXingbie() %>></td> </tr> <tr> <td>所在学院</td> <td><input type="text"name="xueyuan"value=<%=Service.getXueyuan() %>></td> </tr> <tr> <td>职称</td> <td><input type="text"name="zhicheng"value=<%=Service.getZhicheng() %>></td> </tr> </table> <p><input type="submit"value="确定添加"style="100px;height:30px;background-color:#bdd7f2;"></p> </form> </body> </html>
最下面的JSP文件:
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <% // //接收servlet传过来的那个message的参数 //alert是js语句中的弹出警示框,也就是弹出message中的参数 Object message=request.getAttribute("message"); if(!(message==null||message.equals(""))) { %> <script type="text/javascript">alert('<%=message%>')</script> <%} %> <frameset rows="18%,*"> <frame src="http://t.zoukankan.com/Top.jsp" name="top"></frame> <frameset cols="21%,*"> <frame src="http://t.zoukankan.com/Left.jsp" name="left"></frame> <frame src="http://t.zoukankan.com/Right.jsp" name="right"></frame> </frameset> </frameset> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <%@ page language="java" import="Login.Power"%> <title>Insert title here</title> <style type="text/css">body { margin: 0; padding: 0; font-size: 12px; font-family: "Microsoft Yahei", Verdana, Arial, Helvetica, sans-serif } .leftMenu { min-220px; 268px; margin:40px auto 0auto; } .menu { border: #bdd7f2 1px solid; border-top: #0080c4 4px solid; border-bottom: #0080c4 4px solid; background: #f4f9ff repeat-y right; margin-left: 10px; } .menu .ListTitle { border-bottom: 1px #98c9ee solid; display: block; text-align: center; /*position: relative;*/height: 38px; line-height: 38px; cursor: pointer; /*+min-220px;*/ +100%; } .ListTitlePanel { position: relative; } .leftbgbt { position: absolute; background: no-repeat; 11px; height: 52px; left: -11px; top: -4px; } /*.leftbgbt { float:left; background: no-repeat; 11px; height: 52px; left: 0px; top: 0px; zoom:1; z-index:200px; } */.leftbgbt2 { position: absolute; background: no-repeat; 11px; height: 48px; left: -11px; top: -1px; } .menuList { display: block; height: auto; } .menuList div { height: 28px; line-height: 24px; border-bottom: 1px #98c9ee dotted; } .menuList div a { display: block; background: #fff; line-height: 28px; height: 28px; color: #185697; text-decoration: none; } .menuList div a:hover { color: #f30; background: #0080c4; color: #fff; } </style> </head> <% // //接收servlet传过来的那个message的参数 //alert是js语句中的弹出警示框,也就是弹出message中的参数 int message=Power.getFlag(); %> <body style="margin-top:-30px"> <input type="hidden" name="message"value=<%=message %>> <div class="leftMenu"> <div class="menu"> <div class="menuParent"> <div class="ListTitlePanel"> <div class="ListTitle"> <h1><strong>管理</strong></h1> <div class="leftbgbt2"> </div> </div> </div> <div class="menuList" style="text-align:center"> <% if(message==0) { %> <div> <a href="http://t.zoukankan.com/guanli/tianjiajiaoshi.jsp" target="right">添加教师</a></div> <div> <a href="http://t.zoukankan.com/guanli/tianjiaxuesheng.jsp" target="right">添加学生</a></div> <%} %> <% if(message==1) { %> <div> <a href="http://t.zoukankan.com/teacher/tianjiakecheng.jsp" target="right">添加课程</a></div> <div> <a href="http://t.zoukankan.com/${pageContext.request.contextPath}/TXiugaiServlet?method=submit" target="right">修改信息</a></div> <div> <a href="http://t.zoukankan.com/${pageContext.request.contextPath}/LiulanServlet?method=liulan" target="right">浏览选课</a></div> <%} %> <% if(message==2) { %> <div> <a href="http://t.zoukankan.com/${pageContext.request.contextPath}/XuankeServlet?method=submit" target="right">选课</a></div> <div> <a href="http://t.zoukankan.com/${pageContext.request.contextPath}/SXiugaiServlet?method=submit" target="right">修改信息</a></div> <div> <a href="http://t.zoukankan.com/${pageContext.request.contextPath}/LLKCServlet?method=submit" target="right">浏览课程</a></div> <%} %> </div> </div> </div> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>登录</title> </head> <% // //接收servlet传过来的那个message的参数 //alert是js语句中的弹出警示框,也就是弹出message中的参数 Object message=request.getAttribute("message"); if(!(message==null||message.equals(""))) { %> <script type="text/javascript">alert('<%=message%>')</script> <%} %> <body style="margin-top:150px"> <form action="LoginServlet?method=login"method="post"> <table align="center"> <tr> <td>账号:</td> <td><input type="text"name="username"style="150px;height:35px;"></td> </tr> <tr> <td>密码:</td> <td><input type="password"name="password"style="150px;height:35px;"></td> </tr> <tr> <td>身份:</td> <td> <select name="power"> <option value="0">管理员</option> <option value="1">教师</option> <option value="2">学生</option> </select> </td> </tr> </table> <p><input type="submit" value="登录"style="120px;height:35px;margin-left:40%;background-color:#bdd7f2"></p> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Insert title here</title> </head> <% // //接收servlet传过来的那个message的参数 //alert是js语句中的弹出警示框,也就是弹出message中的参数 Object message=request.getAttribute("message"); if(!(message==null||message.equals(""))) { %> <script type="text/javascript">alert('<%=message%>')</script> <%} %> <body> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body style="background-color:#bdd7f2;margin-top:-15px">
<h1 align="center">流转系统</h1>
<strong><a href="http://t.zoukankan.com/Home.jsp" target="_parent" style="text-decoration:none;margin-left:80%">首 页 <a href="http://t.zoukankan.com/Login.jsp" target="_parent" style="text-decoration:none">退出</a></strong>
</body>
</html>
以上的代码均按顺序发出。
现在发一些运行图:
管理员:
学生:
教师: