该系统管理员可以添加和删除学生、教师,教师可以修改自己信息、添加课程、浏览自己课程,学生可以修改自己的信息、选课、浏览全部课程。
首先展示文件:
然后就是一次展示代码:
Guanli包中代码:
package Guanli; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import Login.DBUtil; public class Add { public boolean 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(); } return c; } public boolean 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(); } return c; } public boolean 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(); } return c; } }
package Guanli; import java.sql.Time; import java.text.SimpleDateFormat; import java.util.Date; public class AddService { String username; String password; String name; public String getName() { return name; } public void setName(String name) { this.name = name; } int power; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public int getPower() { return power; } public void setPower(int power) { this.power = power; } }
package Guanli; import java.awt.Desktop.Action; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Login.Power; import Login.Select; /** * Servlet implementation class RegisterServlet */ @WebServlet("/RegisterServlet") public class RegisterServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public RegisterServlet() { super(); // TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { Select s=new Select(); arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); boolean flag; String function=arg0.getParameter("method"); if(function.equals("teacher")) { AddService as=new AddService(); Add a=new Add(); 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=new TeacherService(); 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=new AddService(); Add a=new Add(); 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=new StudentService(); 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); } } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
package Guanli; public class StudentService { String xuehao; String xingming; String xingbie; String banji; String zhuanye; public String getXuehao() { return xuehao; } public void setXuehao(String xuehao) { this.xuehao = xuehao; } public String getXingming() { return xingming; } public void setXingming(String xingming) { this.xingming = xingming; } public String getXingbie() { return xingbie; } public void setXingbie(String xingbie) { this.xingbie = xingbie; } public String getBanji() { return banji; } public void setBanji(String banji) { this.banji = banji; } public String getZhuanye() { return zhuanye; } public void setZhuanye(String zhuanye) { this.zhuanye = zhuanye; } }
package Guanli; public class TeacherService { String gonghao; String xingming; String xingbie; String xueyuan; String zhicheng; public String getGonghao() { return gonghao; } public void setGonghao(String gonghao) { this.gonghao = gonghao; } public String getXingming() { return xingming; } public void setXingming(String xingming) { this.xingming = xingming; } public String getXingbie() { return xingbie; } public void setXingbie(String xingbie) { this.xingbie = xingbie; } public String getXueyuan() { return xueyuan; } public void setXueyuan(String xueyuan) { this.xueyuan = xueyuan; } public String getZhicheng() { return zhicheng; } public void setZhicheng(String zhicheng) { this.zhicheng = zhicheng; } }
Login包里的文件:
package Login; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * 数据库连接工具 * @author Hu * */ public class DBUtil { 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 static Connection getConn () { Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver");//加载驱动 conn = DriverManager.getConnection(db_url, db_user, db_pass); } catch (Exception e) { e.printStackTrace(); } return conn; } /** * 关闭连接 * @param state * @param conn */ public static void close (Statement state, Connection conn) { if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, Statement state, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void main(String[] args) throws SQLException { Connection conn = getConn(); PreparedStatement 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("不空"); } } }
package Login; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class LoginServlet */ @WebServlet("/LoginServlet") public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LoginServlet() { super(); // TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { Select s=new Select(); arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); boolean flag; 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); } } } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
package Login; public class Power { static int flag; public static int getFlag() { return flag; } public static void setFlag(int flag) { Power.flag = flag; } static String xingming; public static String getXingming() { return xingming; } public static void setXingming(String xingming) { Power.xingming = xingming; } static String username; public static String getUsername() { return username; } public static void setUsername(String username) { Power.username = username; } }
package Login; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Select { public boolean select(String table,String username,String password,int num) { 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) { } return f; } }
Student包中的代码:
package Student; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import Login.DBUtil; public class Add { public boolean add(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(); } return c; } }
package Student; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import Login.DBUtil; public class Change { public boolean change(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; } }
package Student; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import Login.DBUtil; public class Find { public boolean find(String table,String id) { boolean c; 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 void findclass(String table,String id) { boolean c; 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 void findjiaoshi(String table,String id) { boolean c; 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) { } } }
package Student; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; import Login.DBUtil; import Teacher.KechengService; public class Get { 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=new KechengService(); 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) { return list; }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=new KechengService(); 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) { return list; }else { return null; } } }
package Student; public class Jieguo { String kechengbianhao; String jiaoshixingming; String gonghao; String xuehao; String xingming; public String getGonghao() { return gonghao; } public void setGonghao(String gonghao) { this.gonghao = gonghao; } public String getKechengbianhao() { return kechengbianhao; } public void setKechengbianhao(String kechengbianhao) { this.kechengbianhao = kechengbianhao; } public String getJiaoshixingming() { return jiaoshixingming; } public void setJiaoshixingming(String jiaoshixingming) { this.jiaoshixingming = jiaoshixingming; } public String getXuehao() { return xuehao; } public void setXuehao(String xuehao) { this.xuehao = xuehao; } public String getXingming() { return xingming; } public void setXingming(String xingming) { this.xingming = xingming; } }
package Student; public class KechengService { static String kechengbianhao; static String kechengmingcheng; static String renkejiaoshi; static int xianyourenshu; static int renshushangxian; public static int getRenshushangxian() { return renshushangxian; } public static void setRenshushangxian(int renshushangxian) { KechengService.renshushangxian = renshushangxian; } public static String getKechengbianhao() { return kechengbianhao; } public static void setKechengbianhao(String kechengbianhao) { KechengService.kechengbianhao = kechengbianhao; } public static String getKechengmingcheng() { return kechengmingcheng; } public static void setKechengmingcheng(String kechengmingcheng) { KechengService.kechengmingcheng = kechengmingcheng; } public static String getRenkejiaoshi() { return renkejiaoshi; } public static void setRenkejiaoshi(String renkejiaoshi) { KechengService.renkejiaoshi = renkejiaoshi; } public static int getXianyourenshu() { return xianyourenshu; } public static void setXianyourenshu(int xianyourenshu) { KechengService.xianyourenshu = xianyourenshu; } }
package Student; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Login.Power; import Teacher.KechengService; /** * Servlet implementation class LLKEServlet */ @WebServlet("/LLKCServlet") public class LLKCServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LLKCServlet() { super(); // TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); boolean flag; 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=new Find(); f.findclass("class", kechengbianhao); arg0.getRequestDispatcher("student/kecheng.jsp").forward(arg0, arg1); } if(function.equals("jiaoshi")) { String gonghao; gonghao=arg0.getParameter("gonghao"); Find f=new Find(); f.findjiaoshi("teacher", gonghao); arg0.getRequestDispatcher("student/jiaoshi.jsp").forward(arg0, arg1); } } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
package Student; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import Login.DBUtil; public class Select { public boolean select(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) { } return c; } }
package Student; public class Service { static String xuehao; static String xingming; static String xingbie; static String banji; static String zhuanye; public static String getXuehao() { return xuehao; } public static void setXuehao(String xuehao) { Service.xuehao = xuehao; } public static String getXingming() { return xingming; } public static void setXingming(String xingming) { Service.xingming = xingming; } public static String getXingbie() { return xingbie; } public static void setXingbie(String xingbie) { Service.xingbie = xingbie; } public static String getBanji() { return banji; } public static void setBanji(String banji) { Service.banji = banji; } public static String getZhuanye() { return zhuanye; } public static void setZhuanye(String zhuanye) { Service.zhuanye = zhuanye; } }
package Student; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Login.Power; /** * Servlet implementation class SXiugaiServlet */ @WebServlet("/SXiugaiServlet") public class SXiugaiServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public SXiugaiServlet() { super(); // TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); boolean flag; String function=arg0.getParameter("method"); if(function.equals("submit")) { Find f=new Find(); f.find("student", Power.getXingming()); arg0.getRequestDispatcher("student/xiugaixinxi.jsp").forward(arg0, arg1); } if(function.equals("xiugai")) { Change c=new Change(); 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); } } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
package Student; public class TeacherService { static String gonghao; static String xingming; static String xingbie; static String xueyuan; static String zhicheng; public static String getGonghao() { return gonghao; } public static void setGonghao(String gonghao) { TeacherService.gonghao = gonghao; } public static String getXingming() { return xingming; } public static void setXingming(String xingming) { TeacherService.xingming = xingming; } public static String getXingbie() { return xingbie; } public static void setXingbie(String xingbie) { TeacherService.xingbie = xingbie; } public static String getXueyuan() { return xueyuan; } public static void setXueyuan(String xueyuan) { TeacherService.xueyuan = xueyuan; } public static String getZhicheng() { return zhicheng; } public static void setZhicheng(String zhicheng) { TeacherService.zhicheng = zhicheng; } }
package Student; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Login.Power; import Teacher.KechengService; /** * Servlet implementation class XuankeServlet */ @WebServlet("/XuankeServlet") public class XuankeServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public XuankeServlet() { super(); // TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); boolean flag; 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=new Change(); Jieguo j=new Jieguo(); Find f=new Find(); 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=new Select(); flag=s.select("jieguo",kechengbianhao,Service.getXuehao()); if(flag) { c.change("class", "xianyourenshu", "kechengbianhao", num+"", kechengbianhao); Add a=new Add(); 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); } } } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
Teacher包中的文件:
package Teacher; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import Login.DBUtil; public class Add { public boolean add(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(); } return c; } }
package Teacher; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import Login.DBUtil; public class Change { public boolean change(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; } }
package Teacher; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import Login.DBUtil; public class Find { public boolean find(String table,String id) { boolean c; 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; } }
package Teacher; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; import Login.DBUtil; public class Get { 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=new KechengService(); 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) { return list; }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=new Xuesheng(); 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) { return list; }else { return null; } } }
package Teacher; public class KechengService { String kechengbianhao; String kechengmingcheng; String renkejiaoshi; int renshushangxian; int xianyourenshu; String gonghao; public String getGonghao() { return gonghao; } public void setGonghao(String gonghao) { this.gonghao = gonghao; } public String getKechengbianhao() { return kechengbianhao; } public void setKechengbianhao(String kechengbianhao) { this.kechengbianhao = kechengbianhao; } public String getKechengmingcheng() { return kechengmingcheng; } public void setKechengmingcheng(String kechengmingcheng) { this.kechengmingcheng = kechengmingcheng; } public String getRenkejiaoshi() { return renkejiaoshi; } public void setRenkejiaoshi(String renkejiaoshi) { this.renkejiaoshi = renkejiaoshi; } public int getRenshushangxian() { return renshushangxian; } public void setRenshushangxian(int renshushangxian) { this.renshushangxian = renshushangxian; } public int getXianyourenshu() { return xianyourenshu; } public void setXianyourenshu(int xianyourenshu) { this.xianyourenshu = xianyourenshu; } }
package Teacher; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Login.Power; import Login.Select; /** * Servlet implementation class KechengServlet */ @WebServlet("/KechengServlet") public class KechengServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public KechengServlet() { super(); // TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { Select s=new Select(); arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); boolean flag; String function=arg0.getParameter("method"); if(function.equals("submit")) { Find f=new Find(); f.find("teacher", Power.getXingming()); Add a=new Add(); KechengService ks=new KechengService(); 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); } } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
package Teacher; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Login.Power; import Login.Select; /** * Servlet implementation class LiulanServlet */ @WebServlet("/LiulanServlet") public class LiulanServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LiulanServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { Select s=new Select(); arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); boolean flag; 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); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
package Teacher; public class Service { static String gonghao; static String xingming; static String xingbie; static String xueyuan; public static String getGonghao() { return gonghao; } public static void setGonghao(String gonghao) { Service.gonghao = gonghao; } public static String getXingming() { return xingming; } public static void setXingming(String xingming) { Service.xingming = xingming; } public static String getXingbie() { return xingbie; } public static void setXingbie(String xingbie) { Service.xingbie = xingbie; } public static String getXueyuan() { return xueyuan; } public static void setXueyuan(String xueyuan) { Service.xueyuan = xueyuan; } public static String getZhicheng() { return zhicheng; } public static void setZhicheng(String zhicheng) { Service.zhicheng = zhicheng; } static String zhicheng; }
package Teacher; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import Login.Power; /** * Servlet implementation class TXiugaiServlet */ @WebServlet("/TXiugaiServlet") public class TXiugaiServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public TXiugaiServlet() { super(); // TODO Auto-generated constructor stub } protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { arg0.setCharacterEncoding("utf-8"); arg1.setCharacterEncoding("utf-8"); boolean flag; String function=arg0.getParameter("method"); if(function.equals("submit")) { Find f=new Find(); f.find("teacher", Power.getXingming()); arg0.getRequestDispatcher("teacher/xiugaixinxi.jsp").forward(arg0, arg1); } if(function.equals("xiugai")) { Change c=new Change(); 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); } } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
package Teacher; public class Xuesheng { String xingming; String xuehao; public String getXingming() { return xingming; } public void setXingming(String xingming) { this.xingming = xingming; } public String getXuehao() { return xuehao; } public void setXuehao(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 align="center" border="1">
<tr>
<td>课程名称</td>
<td>课程编号</td>
<td>任课教师</td>
</tr>
<c:forEach var="stu" items="${all}" >
<tr>
<td><a href="LLKCServlet?method=kecheng&kechengbianhao=${stu.getKechengmingcheng() }">${stu.getKechengmingcheng() }</a></td>
<td>${stu.getKechengbianhao() }</td>
<td><a href="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 align="center" 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="${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 align="center" border="1">
<tr>
<td>课程名称</td>
<td>课程编号</td>
<td>现有人数</td>
</tr>
<c:forEach var="stu" items="${all}" >
<tr>
<td><a href="${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 align="center" 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="Top.jsp" name="top"></frame> <frameset cols="21%,*"> <frame src="Left.jsp" name="left"></frame> <frame src="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 0 auto; } .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="guanli/tianjiajiaoshi.jsp" target="right">添加教师</a></div> <div> <a href="guanli/tianjiaxuesheng.jsp" target="right">添加学生</a></div> <% } %> <% if(message==1) { %> <div> <a href="teacher/tianjiakecheng.jsp" target="right">添加课程</a></div> <div> <a href="${pageContext.request.contextPath}/TXiugaiServlet?method=submit" target="right">修改信息</a></div> <div> <a href="${pageContext.request.contextPath}/LiulanServlet?method=liulan" target="right">浏览选课</a></div> <% } %> <% if(message==2) { %> <div> <a href="${pageContext.request.contextPath}/XuankeServlet?method=submit" target="right">选课</a></div> <div> <a href="${pageContext.request.contextPath}/SXiugaiServlet?method=submit" target="right">修改信息</a></div> <div> <a href="${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="Home.jsp" target="_parent" style="text-decoration:none;margin-left:80%">首 页 <a href="Login.jsp" target="_parent" style="text-decoration:none">退出</a></strong>
</body>
</html>
以上的代码均按顺序发出。
现在发一些运行图:
管理员:
学生:
教师: