在課上的時候完成了管理員登陸界面、管理界面和簡單的學生與教師登錄界面。(后續完成)
下面是原題:
石家庄鐵道大學選課管理系統
1、項目需求:
本項目所開發的學生選課系統完成學校對學生的選課信息的統計與管理,減少數據漏掉的情況,同時也節約人力、物力和財力。告別以往的人工統計。
2.系統要求與功能設計
2.1 頁面要求
(1)能夠在Tomcat服務器中正確部署,並通過瀏覽器查看;
(2)網站頁面整體風格統一;
(3)首頁(登錄頁)要求實現不同用戶登錄后,進入的功能頁不相同。
(4)教師功能頁:有添加課程、修改個人信息、瀏覽選課學生信息三個模塊。
(5)學生功能頁:有修改個人信息、瀏覽課程信息、選課三個功能模塊。
(5)管理員功能頁:有添加教師信息、添加學生信息兩個模塊。
2.2功能要求:
(1)添加教師信息:管理員可以添加教師基本信息,教師基本信息包括:教師工號(八位數字組成,例如02000081)、教師姓名、教師性別、教師所在學院、職稱(教授、副教授、講師、助教)組成;
(2)添加學生信息:管理可以添加學生基本信息,學生基本信息包括學號(八位數字組成,例如20180052)、學生姓名、學生性別、所在班級、所屬專業組成;
(3)添加課程信息:教師登陸后,可以添加自己任職的課程基本信息,課程基本信息包括:課程編號(六位數字組成,例如050013),課程名稱、選課人數、任課教師(任課教師不需錄入,那位教師填寫課程信息,那位教師就是任課教師);
(4)修改個人信息:教師或學生登陸后可以修改個人信息,但教師工號或學號不能修改,另外教師或學生只能修改自己的信息,無法看到或修改其他學生或教師的基本信息。
(5)瀏覽課程信息:學生登陸后可以看到所有課程的列表信息,點擊課程名稱可以查看課程的詳細信息,包括已選課人數;點擊教師名稱可以查看教師的詳細信息。
(6)選課:進入選課頁面,課程信息列表顯示所有選課人數未達到課程設置的選課人數上限,點擊課程名稱可以看到課程詳細信息,點擊課程詳細信息頁面的“選課”按鈕,可以實現選課功能。
(7)瀏覽選課學生信息:教師進入該頁面后,可以看到自己設置的課程信息列表,點擊課程名稱,可以看到,選擇該課程的所有學生基本信息列表。
(8)登陸功能:管理員、教師、學生登陸后可以看到不同的功能頁面,教師或學生登陸后只能看到自己的相關信息,不同教師、不同學生登陸后無法查看其他人的信息。(要求至少創建兩個教師用戶、十個學生用戶演示選課過程)
3數據庫設計:
要求實現課程基本信息表、教師基本信息表、學生基本信息表、選課基本信息表。(提示:選課基本信息包括課程編號、教師編號、學號等基本信息)
4、WEB發布:
要求可以實現在瀏覽器直接訪問系統。
評分等級分類:
A級:起評分90分,要求完全按照要求實現全部功能。(結合以前成績綜合考量,確認為免試);
B級:起評分80分,最高分不超過89分,可以完成選課的基本流程,實現教師、學生、課程基本信息添加、選課功能實現,剩余功能有兩個以下(包括兩個)未實現;
C級:起評分70分,最高分不超過79分,可以實現教師、學生、課程基本信息添加、修改個人信息,無法實現選課功能;
D級:起評分60分,最高分不超過69分,可以完成教師、學生、課程兩個以上(包括兩個)基本信息添加;
E級:無法達到上述級別要求。
以下是所建的表格(連接數據庫、與數據庫進行數據交互):
所有表格 管理員:
學生:
老師:
以下是包裝的類:
連接數據庫操作:
import java.sql.Connection; import java.sql.DriverManager; 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/homework?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true"; public static String db_user = "root"; public static String db_pass = "101032"; public static Connection getConn () { Connection conn = null; try { //加載驅動 Class.forName("com.mysql.jdbc.Driver"); //獲取連接 conn = DriverManager.getConnection(db_url, db_user, db_pass); System.out.println("連接成功!"); } catch (Exception e) { e.printStackTrace(); } return conn; } public static void main(String[] args) { getConn(); } /** * @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(); } } } }
管理員Bean:
public class users { private String name; private String password; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
學生Bean:
public class user { private String id; private String name; private String password; private String realname; private String sex; private String number; private String adress; public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getRealname() { return realname; } public void setRealname(String realname) { this.realname = realname; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getnumber() { return number; } public void setnumber(String number) { this.number = number; } public String getAdress() { return adress; } public void setAdress(String adress) { this.adress = adress; } public String getId() { return id; } }
老師Bean:
public class tuser { private String id; private String name; private String password; private String realname; private String sex; private String number; private String adress; public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getRealname() { return realname; } public void setRealname(String realname) { this.realname = realname; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getnumber() { return number; } public void setnumber(String number) { this.number = number; } public String getAdress() { return adress; } public void setAdress(String adress) { this.adress = adress; } public String getId() { return id; } }
管理員Dao:(學生和老師的Dao類似)
import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.sql.SQLException; import com.util.DBUtil; public class dengluDao { public static String searchUsername(String name) { String sql="select * from admin where "; if(name!=null) { sql=sql+"name like+'%"+name+"%'"; } Connection conn=DBUtil.getConn(); Statement state=null; ResultSet rs=null; String name1=null; try { state=conn.createStatement(); rs=state.executeQuery(sql); while(rs.next()) { name1=rs.getString("name"); } } catch (Exception e) { e.printStackTrace(); }finally{ DBUtil.close(rs,state, conn); } return name1; } public static String searchPassword(String name) { String sql="select * from admin where "; if(name!=null) { sql=sql+"name like '%"+name+"%'"; } Connection conn=DBUtil.getConn(); Statement state=null; ResultSet rs=null; String password1=null; try { state=conn.createStatement(); rs=state.executeQuery(sql); while(rs.next()) { password1=rs.getString("password"); } } catch (Exception e) { e.printStackTrace(); }finally { DBUtil.close(rs,state,conn); } return password1; } }
刪除:
import java.sql.Connection; import java.sql.SQLException; import com.mysql.jdbc.PreparedStatement; import com.util.DBUtil; public class DeleteDao { Connection conn = DBUtil.getConn(); //連接數據庫 public boolean delete(String username) { boolean flag=false; try { String sql="delete from homework where name='"+username+"'"; PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(sql); int i = pstmt.executeUpdate(); pstmt.close(); conn.close(); if(i>0) flag = true; }catch(SQLException e) { System.out.println("刪除失敗"); e.printStackTrace(); } return flag; } }
添加學生:
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import com.domain.user; import com.util.DBUtil; public class RegisterDao { /** * 用戶注冊 * @param user * @return */ public boolean register(user user) { /*`id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `password` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `realname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `sex` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `area` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `email` varchar(50)*/ String sql = "insert into homework(name,password,realname,sex,number,adress) values(?,?,?,?,?,?)"; Connection conn = DBUtil.getConn(); //連接數據庫 PreparedStatement pstmt = null; int count = 0; try { pstmt = conn.prepareStatement(sql);//用於將 SQL 語句發送到數據庫中。 pstmt.setString(1,user.getName());//1代表第一列 pstmt.setString(2,user.getPassword()); pstmt.setString(3,user.getRealname()); pstmt.setString(4,user.getSex()); pstmt.setString(5,user.getnumber()); pstmt.setString(6,user.getAdress()); count = pstmt.executeUpdate();//返回的是受影響的行數(即更新的行數) } catch (SQLException e) { // TODO 自動生成的 catch 塊 e.printStackTrace(); } if(count>0) { return true; } return false; } }
顯示:
import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.domain.user; import com.mysql.jdbc.PreparedStatement; import com.mysql.jdbc.ResultSet; import com.mysql.jdbc.Statement; import com.util.DBUtil; public class ShowDao { public List<user> select(){ Connection conn = DBUtil.getConn(); //連接數據庫 List<user> list = new ArrayList<user>(); try { String sql="select * from homework"; Statement pstmt = (Statement) conn.createStatement(); ResultSet rs = (ResultSet) pstmt.executeQuery(sql); while(rs.next()) { user user=new user(); user.setId("id"); user.setName(rs.getString("name")); user.setPassword(rs.getString("password")); user.setRealname(rs.getString("realname")); user.setSex(rs.getString("sex")); user.setnumber(rs.getString("number")); user.setAdress(rs.getString("adress")); list.add(user); } System.out.println("hhh"); rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; } }
更新:
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.util.DBUtil; public class UpdateDao { //Connection conn = DBUtil.getConn(); //連接數據庫 public boolean update(String name, String password,String realname, String sex,String number,String adress) { boolean flag = false; String sql="update homework set sex ='"+sex +"' where password='"+password+"'"; Connection conn = DBUtil.getConn(); //連接數據庫 try { PreparedStatement ps =conn.prepareStatement(sql); int i = ps.executeUpdate(); System.out.println("1111"); if(i>0) flag = true; System.out.println(flag); System.out.println(i); ps.close(); conn.close(); } catch (SQLException e) { // TODO: handle exception System.out.println("更新失敗"); e.printStackTrace(); } return flag; } }
Service層:
import com.dao.RegisterDao; import com.domain.user; public class RegisterService { private RegisterDao dao = new RegisterDao(); /** * 用於用戶注冊 * @param user * @return */ public boolean register(user user) { boolean registerSuccess = false; registerSuccess = dao.register(user);//判斷是否存入數據庫成功 return registerSuccess; } }
import java.util.List; import com.dao.ShowDao; import com.domain.user; public class ShowService { private ShowDao sd=new ShowDao(); public List<user> list() { return sd.select(); } }
Servlet層:
登錄(管理員)
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 com.dao.dengluDao; /** * Servlet implementation class IndexServlet */ @WebServlet("/IndexServlet") public class dengluServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public dengluServlet() { super(); // TODO Auto-generated constructor stub } dengluDao dao=new dengluDao(); /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String name=request.getParameter("name"); String password=request.getParameter("password"); String rname=dao.searchUsername(name); String rpassword=dao.searchPassword(name); if(name.equals(rname)&&password.equals(rpassword)) { request.getRequestDispatcher("index.jsp").forward(request, response); System.out.println("IndexServlet跳轉成功"); } else { request.getRequestDispatcher("denglu.jsp").forward(request,response); System.out.println("IndexServlet跳轉失敗"); System.out.println(name+password); System.out.println(rname+rpassword); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("UTF-8"); String method=request.getParameter("method"); if("search".equals(method)) { doGet(request, response); } } }
刪除(學生)
import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.dao.DeleteDao; import com.domain.user; import com.util.DBUtil; /** * Servlet implementation class DeleteServlet */ public class DeleteServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public DeleteServlet() { 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 request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String name = request.getParameter("name"); String password=request.getParameter("password"); /*String classteacher=request.getParameter("classteacher"); String classplace=request.getParameter("classplace");*/ user user = new user(); user.setName(name); user.setPassword(password); /*school.setclassteacher(classteacher); school.setclassplace(classplace); */ //查找要刪除的用戶和密碼 //String sql = "SELECT * FROM homework WHERE name='"+name+"' AND password='"+password+"'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; DeleteDao sd = new DeleteDao(); try { state = conn.createStatement(); //rs = state.executeQuery(sql);//executeQuery()返回包含給定查詢所生成數據的 ResultSet 對象,如果沒有查詢到信息,返回一個next()為false的ResultSet 對象 //if(rs.next()) { sd.delete(name); response.setCharacterEncoding("gbk"); PrintWriter out = response.getWriter(); out.println("<script> alert('刪除成功'); window.location.href='ShowServlet'; </script>"); //response.sendRedirect(request.getContextPath() + "/delete.jsp"); //} //else {response.setCharacterEncoding("gbk"); //PrintWriter out = response.getWriter(); //out.println("<script> alert('刪除失敗,用戶不存在或輸入有誤'); window.location.href='delete.jsp'; </script>");} }catch(Exception e) { System.out.println("刪除失敗"); e.printStackTrace(); } } /** * @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); } }
添加(學生)
import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.domain.user; import com.service.RegisterService; import com.util.DBUtil; /** * Servlet implementation class RegisterServlet */ public class RegisterServlet extends HttpServlet { private static final long serialVersionUID = 1L; private RegisterService Ser = new RegisterService(); /** * @see HttpServlet#HttpServlet() */ public RegisterServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); //getParameter()獲取的是客戶端設置的數據。 String password = request.getParameter("password"); String realname = request.getParameter("realname"); String sex = request.getParameter("sex"); String number = request.getParameter("number"); String adress = request.getParameter("adress"); //String Strsql="select name from homework where name=? "; //String[] params= {name}; String sql = "select name from homework where "; if (name != "") { sql += "name like '%" + name + "%'"; } Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql);//executeQuery()返回包含給定查詢所生成數據的 ResultSet 對象,如果沒有查詢到信息,返回一個next()為false的ResultSet 對象 if(rs.next()==false) { //name = rs.getString("name"); user user = new user(); user.setName(name); user.setPassword(password); user.setRealname(realname); user.setSex(sex); user.setnumber(number); user.setAdress(adress); response.setCharacterEncoding("gbk"); PrintWriter out = response.getWriter(); System.out.println(" "+user.getName()+" "+user.getPassword()+" "+user.getRealname()+" "+user.getSex()+" "+user.getnumber()); if(Ser.register(user)) { out.println("<script> alert('添加成功!'); window.location.href='ShowServlet'; </script>"); }else { out.println("<script> alert('添加失敗!'); window.location.href='register.jsp'; </script>"); } out.println("</HTML>"); out.flush(); //out.flush()表示強制將緩沖區中的數據發送出去,不必等到緩沖區滿 out.close(); } else {response.setCharacterEncoding("gbk"); PrintWriter out = response.getWriter(); out.println("<script> alert('該用戶已存在,添加失敗!'); window.location.href='register.jsp'; </script>"); out.println("</HTML>"); out.flush(); //out.flush()表示強制將緩沖區中的數據發送出去,不必等到緩沖區滿 out.close(); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } } /** * @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); } }
顯示(學生)
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.ShowDao;
import com.domain.user;
import com.service.*;
/**
* Servlet implementation class ShowServlet
*/
public class ShowServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ShowServlet() {
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
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//String name = request.getParameter("name");
//String password = request.getParameter("password");
//String realname = request.getParameter("realname");
//String sex = request.getParameter("sex");
//String number = request.getParameter("number");
//String email = request.getParameter("email");
//ShowService ss=new ShowService();
//List<user> list = ss.list();
ShowDao sd = new ShowDao();
List<user> list = sd.select();
request.setAttribute("list", list);
System.out.println("hhhhh");
request.getRequestDispatcher("show.jsp").forward(request, response);
}
/**
* @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);
}
}
更新(學生):
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.dao.UpdateDao; import com.domain.*; /** * Servlet implementation class UpdateServlet */ public class UpdateServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public UpdateServlet() { 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 //String id1 = request.getParameter("id"); //int id = Integer.parseInt((String)request.getParameter("id")); request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); String password = request.getParameter("password"); String realname = request.getParameter("realname"); String sex = request.getParameter("sex"); String number = request.getParameter("number"); String adress = request.getParameter("adress"); ///System.out.println("------------------------------------"+id); UpdateDao ud = new UpdateDao(); try { if(ud.update(name, password, realname, sex, number,adress)){ //request.setAttribute("xiaoxi", "更新成功"); //request.getRequestDispatcher("/ShowServlet").forward(request, response); System.out.println("meiyou"); request.getRequestDispatcher("/ShowServlet").forward(request, response); //request.getRequestDispatcher("/ShowServlet").forward(request, response); } else {PrintWriter out = response.getWriter(); out.println("<script> alert('更新失敗'); window.location.href='ShowServlet'; </script>");} }catch(Exception e){ //response.sendRedirect("index.jsp"); PrintWriter out = response.getWriter(); out.println("<script> alert('更新失敗'); window.location.href='ShowServlet'; </script>"); e.printStackTrace(); } } /** * @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); } }
jsp:
選課系統:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>石家庄鐵道大學選課管理系統</title>
</head>
<body>
<div align="center">
<h2>管理界面</h2>
<a href="denglu.jsp">管理員登陸</a>
<a href="denglu1.jsp">學生登陸</a>
<a href="denglu2.jsp">教師登陸</a>
</div>
</body>
</html>
登錄界面:(管理員)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登錄</title> <!-- Bootstrapvalidate導入 --> <link rel="stylesheet" href="${pageContext.request.contextPath }/plug-ins/css/bootstrapValidator.css" /> <link href="${pageContext.request.contextPath}/plug-ins/css/demo.css" rel="stylesheet" type="text/css"> <!-- Bootstrap --> <link href="${pageContext.request.contextPath}/plug-ins/css/bootstrap.css" rel="stylesheet"> <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依賴 jQuery,所以必須放在前邊) --> <script src="${pageContext.request.contextPath}/plug-ins/js/jquery-1.10.2.min.js"></script> <!-- 加載 Bootstrap 的所有 JavaScript 插件。你也可以根據需要只加載單個插件。 --> <script src="${pageContext.request.contextPath}/plug-ins/js/bootstrap.js"></script> </head> <body> <div class="col-lg-8 col-lg-offset-2"> <div class="page-header"> <div style="background-color:rgb(255,255,0)"> <h1 >管理員登錄</h1> </div> <h2>登錄</h2> <form action="${pageContext.request.contextPath }/dengluServlet?method=search" class="form-horizontal" role="form"> <div class="form-group"> <label class="col-lg-3 control-label">賬號:</label> <div class="col-lg-8"> <input type="text" class="form-control" name="name" placeholding="賬號"/> </div> <label class="col-lg-3 control-label">密碼:</label> <div class="col-lg-8"> <input type="password" class="form-control" name="password" placeholding="密碼"/> </div> <div> <button type="submit" class="btn bvtn-primary">登錄</button> </div> </div> </form> </div> </div> </body> </html>
管理員管理界面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主界面</title>
</head>
<body>
<div align="center">
<h2>管理界面</h2>
<a href="register.jsp">學生添加</a>
<a href="register1.jsp">教師添加</a>
<a href="ShowServlet">查詢學生信息</a>
<a href="ShowServlet1">查詢教師信息</a>
<a href="xuankexitong.jsp">退出</a>
</div>
</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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>用戶添加</title> <!-- Bootstrapvalidate導入 --> <link rel="stylesheet" href="${pageContext.request.contextPath }/plug-ins/css/bootstrapValidator.css" /> <link href="${pageContext.request.contextPath}/plug-ins/css/demo.css" rel="stylesheet" type="text/css"> <!-- Bootstrap --> <link href="${pageContext.request.contextPath}/plug-ins/css/bootstrap.css" rel="stylesheet"> <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依賴 jQuery,所以必須放在前邊) --> <script src="${pageContext.request.contextPath}/plug-ins/js/jquery-1.10.2.min.js"></script> <!-- 加載 Bootstrap 的所有 JavaScript 插件。你也可以根據需要只加載單個插件。 --> <script src="${pageContext.request.contextPath}/plug-ins/js/bootstrap.js"></script> <!-- validate表單驗證導入 --> <script type="text/javascript" src="${pageContext.request.contextPath}/plug-ins/js/bootstrapValidator.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/plug-ins/js/bootstrapValidator_zh_CN.js"></script> <!-- Font Awesome --> <link rel="stylesheet" href="${pageContext.request.contextPath}/plug-ins/css/font-awesome.min.css"> <script type="text/javascript"> $(function() { //#''單引號里面是下面form標簽的id $('#registe').bootstrapValidator( { message : 'This value is not valid', feedbackIcons : { valid : 'glyphicon glyphicon-ok', invalid : 'glyphicon glyphicon-remove', validating : 'glyphicon glyphicon-refresh' }, fields : { name : { validators : { notEmpty : { message : '姓名不能為空' }, stringLength : { min : 1, max : 12, message : '姓名由1-12個字符組成' }, regexp : { regexp : /[\u4E00-\u9FA5]+$/, message : '姓名只能由中文組成' } } }, password:{ validators:{ notEmpty : { message : '密碼不能為空' }, stringLength : { min : 1, max : 8, message : '密碼必須由1-8個字母數字組成' }, regexp : { regexp : /^[a-zA-Z0-9]+$/, message : '密碼只能由字母數字組成' } } }, realname:{ validators:{ notEmpty : { message : '所屬班級不能為空' } } }, number:{ validators:{ notEmpty : { message : '學號不能為空' }, stringLength : { min : 1, max : 8, message : '學號必須由1-8位字符組成' }, regexp : { regexp : /^2018(\d{4})+$/, message : '請輸入正確的學號' } } }, }, }); }); </script> </head> <body> <div class="col-lg-8 col-lg-offset-2"> <div class="page-header"> <h2>信息登記</h2> </div> <form id="registe" method="post" class="form-horizontal" action="${pageContext.request.contextPath }/RegisterServlet"> <div class="form-group"> <label class="col-lg-3 control-label">姓名:</label> <div class="col-lg-4"> <input type="text" class="form-control" name="name" placeholder="請輸入姓名" /> </div> </div> <div class="form-group"> <label class="col-lg-3 control-label">密碼:</label> <div class="col-lg-5"> <input type="password" class="form-control" name="password" placeholder="請輸入密碼" /> </div> </div> <div class="form-group"> <label class="col-lg-3 control-label">所屬班級:</label> <div class="col-lg-5"> <input type="text" class="form-control" name="realname" placeholder="請輸入所屬班級" /> </div> </div> <div class="form-group"> <label class="col-lg-3 control-label">性別:</label> <div class="col-lg-5"> <input type="radio" name="sex" value="man" checked="checked"/> 男 <input type="radio" name="sex" value="woman" /> 女 </div> </div> <div class="form-group"> <label class="col-lg-3 control-label">學號:</label> <div class="col-lg-5"> <input type="text" class="form-control" name="number" placeholder="請輸入學號"/> </div> </div> <div class="form-group"> <label class="col-lg-3 control-label">所在學院:</label> <div class="col-lg-5"> <input type="text" class="form-control" name="adress" placeholder="請輸入學院"/> </div> </div> <div class="form-group"> <div class="col-lg-3 col-lg-offset-3"> <button type="submit" class="btn btn-primary">添加</button> </form> <!-- <div><a href="delete.jsp"><font SIZE="4" >刪除用戶</font></a></div> <div><a href="ShowServlet"><font SIZE="4" >查看用戶</font></a></div> --> <div><a href="index.jsp"><font SIZE="4" >返回</font></a></div> </div> </body> </html>
顯示學生:
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <base href="<%=basePath%>"> <title>志願者信息頁面</title> </head> <body> <h1>${xiaoxi}</h1> <table width="600" border="1" cellpadding="0" > <tr> <th>姓名</th> <th>密碼</th> <th>所在班級</th> <th>性別</th> <th>學號</th> <th>所屬學院</th> <th>操作:</th> </tr> <c:forEach var="U" items="${list}" > <form action="UpdateServlet" method="post"> <tr> <td><input type="text" value="${U.name}" name="name"></td> <td><input type="text" value="${U.password}" name="password"></td> <td><input type="text" value="${U.realname}" name="realname"></td> <td><input type="text" value="${U.sex}" name="sex"></td> <td><input type="text" value="${U.number}" name="number"></td> <td><input type="text" value="${U.adress}" name="adress"></td> <td><a onclick="return check()" href="DeleteServlet?name=${U.name}">刪除</a> <input type="submit" value="更新"/></td> </tr> </form> </c:forEach> <form id="registe" method="post" class="form-horizontal" action="${pageContext.request.contextPath }/Show1Servlet"> <tr> <td><input type="text" class="form-control" name="name" placeholder="請輸入姓名"></td> <td><input type="text" class="form-control" name="realname" placeholder="請輸入所屬班級"></td> <td><input type="text" class="form-control" name="sex" placeholder="請輸入性別"></td> <td><input type="text" class="form-control" name="number" placeholder="請輸入學號"></td> </tr> <button type="submit" class="btn btn-primary">查詢</button> </form> <div><a href="index.jsp"><font SIZE="4" >返回</font></a></div> </table> <script type="text/javascript"> function check() { if (confirm("是否確認刪除該志願者信息?")){ return true; }else{ return false; } } </script> </body> </html>
以上的是今天下午完成的,其余的功能后續完成。