zoukankan      html  css  js  c++  java
  • 学生信息管理与选课系统

    此系统针对学生管理和选课开发,功能并不完善。

    面向对象主要有管理员,教师和学生。

    管理员可管理教师、学生等用户信息,教师发布课程,学生可进行选课。

    数据库表分为课表(Clas),学生表(User_Student),教师表(User_Teacher),用户表(userr).

     

     

    以下为登录界面:

     对登陆的各种情况进行判断,判断成功后将用户类别和id存储在session中,跳转至主界面,

      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <!DOCTYPE html>
      4 <html>
      5 <head>
      6 <title>A d m i n</title>
      7 <style type="text/css">
      8 div {
      9     align: center;
     10 }
     11 
     12 html {
     13     background-color: gray;
     14 }
     15 
     16 .de {
     17     border-radius: 3px;
     18     background-color: rgba(255, 255, 255, 0.2);
     19     width: 400px;
     20     height: 50px;
     21     margin-top: 20px;
     22     margin-bottom: 20px;
     23     color: #FFF;
     24     lighting-color: black;
     25 }
     26 
     27 #title {
     28     padding-top: 30px;
     29     color: white;
     30 }
     31 
     32 #mainwindow {
     33     font-family: 黑体;
     34     font-size: 40px;
     35     lighting-color: white;
     36     height: 400px;
     37     width: 500px;
     38     background: rgba(211, 255, 199, 0.5);
     39     margin-top: 200px;
     40 }
     41 
     42 a {
     43     color: white;
     44     text-decoration: none;
     45 }
     46 
     47 a:hover {
     48     background-color: pink;
     49 }
     50 
     51 .a {
     52     width: 250px;
     53     float: left;
     54     font-size: 20px;
     55     text-align: center;
     56 }
     57   table
     58         {
     59             width:1100px;
     60             height:500px;
     61             border-collapse: collapse;
     62             margin: 0 auto;
     63             text-align: center;
     64         }
     65         table td, table th
     66         {
     67             border: 1px solid #cad9ea;
     68             color: #666;
     69             height: 30px;
     70         }
     71         table thead th
     72         {
     73             background-color: #CCE8EB;
     74             width: 100px;
     75         }
     76         table tr:nth-child(odd)
     77         {
     78             background: #fff;
     79         }
     80         table tr:nth-child(even)
     81         {
     82             background: #F5FAFA;
     83         }
     84                 
     85     button { /* 按钮美化 */
     86     width: 270px; /* 宽度 */
     87     height: 40px; /* 高度 */
     88     border-width: 0px; /* 边框宽度 */
     89     border-radius: 3px; /* 边框半径 */
     90     background: #1E90FF; /* 背景颜色 */
     91     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
     92     outline: none; /* 不显示轮廓线 */
     93     font-family: Microsoft YaHei; /* 设置字体 */
     94     color: white; /* 字体颜色 */
     95     font-size: 17px; /* 字体大小 */
     96 }
     97     button:hover { /* 鼠标移入按钮范围时改变颜色 */
     98     background: #5599FF;
     99 </style>
    100 <%
    101     String message = (String) session.getAttribute("message");
    102     if (message != null) {
    103 %>
    104 <script type="text/javascript">
    105     alert("<%=message%>");
    106 </script>
    107 <%
    108     session.removeAttribute("message");
    109     }
    110 %>
    111 <script type="text/javascript">
    112     function sentence(form) {
    113         var flag = true;
    114         username = form.idusername.value;
    115         password = form.password.value;
    116         if (username == "") {
    117             alert("username cant be null");
    118             return false;
    119         }
    120         if (password == "") {
    121             alert("password cant be null");
    122             return false;
    123         }
    124         if (!username.match("[a-zA-Z0-9_]")) {
    125             alert("用户id不能包含特殊字符!");
    126             return false;
    127         }
    128         if (!password.match("[a-zA-Z0-9_]")) {
    129             alert("密码只能包含数字字母下划线!");
    130             return false;
    131         }
    132         return true;
    133     }
    134 </script>
    135 </head>
    136 <body>
    137     <center>
    138         <div id="mainwindow">
    139             <div id="title">用户登录</div>
    140             <div id="form">
    141 
    142                 <form action="log" name="logf" id="logf" onsubmit="return sentence(logf)">
    143                 <input type="text" placeholder="账号" class="de" name="username"><br>
    144                 <input type="password" placeholder="密码" class="de" name="password"><br> 
    145                 <input type="submit" value="Login"class="de" id="submit"><br>
    146                     <div class="a">
    147                         <a href="#">忘记密码</a>
    148                     </div>
    149                     <div class="a">
    150                         <a href="#">注册账号</a>
    151                     </div>
    152                 </form>
    153             </div>
    154         </div>
    155     </center>
    156 </body>
    157 
    158 
    159 </html>
    LogIn.jsp
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 
     9 import javax.servlet.ServletException;
    10 import javax.servlet.annotation.WebServlet;
    11 import javax.servlet.http.HttpServlet;
    12 import javax.servlet.http.HttpServletRequest;
    13 import javax.servlet.http.HttpServletResponse;
    14 @WebServlet("/log")
    15 public class log extends HttpServlet {
    16     private static final long serialVersionUID = 1L;
    17     public log() {
    18         super();
    19         // TODO Auto-generated constructor stub
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         String name=request.getParameter("username");
    23         String pass=request.getParameter("password");
    24         String usertype="";
    25         int flag=0;
    26         Link l=new Link();
    27         try {
    28             Connection con=l.lin("Class_Select");
    29             Statement stmt=con.createStatement();
    30             String s="select * from userr";
    31             ResultSet rsst=stmt.executeQuery(s);
    32             while(rsst.next()) {
    33                 if((name.equals(rsst.getString("username")))&&(pass.equals(rsst.getString("password")))) {
    34                     flag=1;
    35                     usertype=rsst.getString(3);
    36                     System.out.println(usertype);
    37                 }
    38             }
    39             rsst.close();
    40             stmt.close();
    41             con.close();
    42             
    43         } catch (SQLException e) {
    44             // TODO Auto-generated catch block
    45             e.printStackTrace();
    46         }
    47         if(flag==1) {
    48             request.getSession().removeAttribute("usertype");
    49             request.getSession().removeAttribute("userid");
    50             request.getSession().setAttribute("usertype",usertype);
    51             request.getSession().setAttribute("userid", name);
    52             request.getRequestDispatcher("MainWindow.jsp").forward(request, response);
    53         }
    54         else{
    55             request.getSession().setAttribute("message", "账号或密码错误!");
    56             request.getRequestDispatcher("Login.jsp").forward(request, response);
    57         }
    58     
    59     }
    60     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    61         // TODO Auto-generated method stub
    62         doGet(request, response);
    63     }
    64 
    65 }
    Log.java

    在主界面的jsp中调用session判断用户类型,显示不同的选项:

    管理员主界面:

    教师主界面:

    学生主界面:

      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 <!DOCTYPE html>
      5 <html>
      6 <head>
      7 <meta charset="UTF-8">
      8 <title>Document</title>
      9 <style type="text/css">
     10 
     11         #d1{
     12             text-align: center;
     13             padding-top: 40px;
     14             font-family: "微软雅黑";
     15             font-size: 40px;
     16             background-color: #DDDDDD;
     17             height: 100px;
     18         }
     19         div ul{
     20             vertical-align: top;
     21             list-style-type: none;
     22             margin: 0px;
     23             vertical-align: left;
     24             width: 200px;
     25             padding: 0px;
     26             border-top: 20px solid #F8A0E7;
     27             border-bottom :20px solid #F8A0E7;
     28         }
     29         .headd{
     30             font-family: "微软雅黑";
     31             lighting-color: red;
     32             font-size: 20px;
     33         }
     34         div li a{
     35             height: 80px;
     36             display: block;
     37             padding: 0px 0px 0px 0em;
     38             text-decoration: none;
     39             border-left: 20px solid pink;
     40         }
     41         div li a:link,div li a:visited{
     42             background-color: #F0F0F0;
     43             color: #461737;
     44         }
     45         div li a:hover{
     46             background-color: green;
     47             color: gray;
     48         }
     49         div li a:active{
     50             background-color: pink;
     51         }
     52         #left{
     53         float:left;
     54         }
     55         #right{
     56         height:400px;
     57         width:1100px;
     58         float:left;
     59         }
     60         #inp{
     61         float:left;
     62         height:400px;
     63         width:1202px;
     64         }
     65         .btn{
     66         float:left;
     67         }
     68           table
     69         {
     70             width:1100px;
     71             height:500px;
     72             border-collapse: collapse;
     73             margin: 0 auto;
     74             text-align: center;
     75         }
     76         table td, table th
     77         {
     78             border: 1px solid #cad9ea;
     79             color: #666;
     80             height: 30px;
     81         }
     82         table thead th
     83         {
     84             background-color: #CCE8EB;
     85             width: 100px;
     86         }
     87         table tr:nth-child(odd)
     88         {
     89             background: #fff;
     90         }
     91         table tr:nth-child(even)
     92         {
     93             background: #F5FAFA;
     94         }
     95                 
     96     button { /* 按钮美化 */
     97     width: 270px; /* 宽度 */
     98     height: 40px; /* 高度 */
     99     border-width: 0px; /* 边框宽度 */
    100     border-radius: 3px; /* 边框半径 */
    101     background: #1E90FF; /* 背景颜色 */
    102     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    103     outline: none; /* 不显示轮廓线 */
    104     font-family: Microsoft YaHei; /* 设置字体 */
    105     color: white; /* 字体颜色 */
    106     font-size: 17px; /* 字体大小 */
    107 }
    108     button:hover { /* 鼠标移入按钮范围时改变颜色 */
    109     background: #5599FF;
    110 
    111 </style>
    112 </head>
    113 <body onload="Onload()">
    114     <div id="d1">学生信息管理系统</div>
    115     <div id="left">
    116     <%
    117     String message = (String) session.getAttribute("message");
    118     if (message != null) {
    119 %>
    120 <script type="text/javascript">
    121     alert("<%=message%>");
    122 </script>
    123 <%
    124     session.removeAttribute("message");
    125     }
    126 %>
    127 <ul>
    128     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    129     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    130     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    131     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    132     <li><a href="AddUser.jsp">用户录入</a></li>
    133     <li><a href="ShowStudent">学生信息</a></li>
    134     <li><a href="ShowTeacher">教师信息</a></li>
    135     <li><a href="ShowUser">用户信息</a></li>
    136     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    137     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    138     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    139     <li><a href="Update.jsp">修改信息</a></li>
    140     <li><a href="ShowClass">选课</a></li>
    141     <li><a href="HaveSelected">已选课</a>
    142     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    143     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    144     <li><a href="AddClass.jsp">添加课程</a></li>
    145     <li><a href="ShowTeaClas">自己的课程</a></li>
    146     <%} %>    
    147     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    148 </ul>
    149 </div>
    150 <div id="right">
    151 <h1>学生信息管理系统</h1>
    152 </div>
    153 </body>
    154 </html>
    MainWindow.jsp

     管理员功能页:

    添加学生信息:

     将学生信息录入到学生表和用户表中

    添加成功后提示并跳回添加学生界面

    以下教师信息录入与用户录入相似,

    教师信息录入到教师表和用户表中,用户录入只录入到用户表

     

      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 <!DOCTYPE html>
      5 <html>
      6 <head>
      7 <meta charset="UTF-8">
      8 <title>Document</title>
      9 <style type="text/css">
     10     
     11         #d1{
     12             text-align: center;
     13             padding-top: 40px;
     14             font-family: "微软雅黑";
     15             font-size: 40px;
     16             background-color: #DDDDDD;
     17             height: 100px;
     18         }
     19         div ul{
     20             vertical-align: top;
     21             list-style-type: none;
     22             margin: 0px;
     23             vertical-align: left;
     24             width: 200px;
     25             padding: 0px;
     26             border-top: 20px solid #F8A0E7;
     27             border-bottom :20px solid #F8A0E7;
     28         }
     29         .headd{
     30             font-family: "微软雅黑";
     31             lighting-color: red;
     32             font-size: 20px;
     33         }
     34         div li a{
     35             height: 80px;
     36             display: block;
     37             padding: 0px 0px 0px 0em;
     38             text-decoration: none;
     39             border-left: 20px solid pink;
     40         }
     41         div li a:link,div li a:visited{
     42             background-color: #F0F0F0;
     43             color: #461737;
     44         }
     45         div li a:hover{
     46             background-color: green;
     47             color: gray;
     48         }
     49         div li a:active{
     50             background-color: pink;
     51         }
     52         #left{
     53         float:left;
     54         }
     55         #right{
     56         height:400px;
     57         width:1100px;
     58         float:left;
     59         }
     60         #inp{
     61         float:left;
     62         height:400px;
     63         width:1202px;
     64         }
     65         .btn{
     66         float:left;
     67         }
     68           table
     69         {
     70             width:1100px;
     71             height:500px;
     72             border-collapse: collapse;
     73             margin: 0 auto;
     74             text-align: center;
     75         }
     76         table td, table th
     77         {
     78             border: 1px solid #cad9ea;
     79             color: #666;
     80             height: 30px;
     81         }
     82         table thead th
     83         {
     84             background-color: #CCE8EB;
     85             width: 100px;
     86         }
     87         table tr:nth-child(odd)
     88         {
     89             background: #fff;
     90         }
     91         table tr:nth-child(even)
     92         {
     93             background: #F5FAFA;
     94         }
     95                 
     96     button { /* 按钮美化 */
     97     width: 270px; /* 宽度 */
     98     height: 40px; /* 高度 */
     99     border-width: 0px; /* 边框宽度 */
    100     border-radius: 3px; /* 边框半径 */
    101     background: #1E90FF; /* 背景颜色 */
    102     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    103     outline: none; /* 不显示轮廓线 */
    104     font-family: Microsoft YaHei; /* 设置字体 */
    105     color: white; /* 字体颜色 */
    106     font-size: 17px; /* 字体大小 */
    107 }
    108     button:hover { /* 鼠标移入按钮范围时改变颜色 */
    109     background: #5599FF;
    110 
    111 </style>
    112     <%
    113     String message = (String) session.getAttribute("message");
    114     if (message != null) {
    115 %>
    116 <script type="text/javascript">
    117     alert("<%=message%>");
    118 </script>
    119 <%
    120     session.removeAttribute("message");
    121     }
    122 %>
    123 
    124 
    125 </head>
    126 <body onload="Onload()">
    127     <div id="d1">学生管理系统</div>
    128     <div id="left">
    129 <ul>
    130     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    131     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    132     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    133     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    134     <li><a href="AddUser.jsp">用户录入</a></li>
    135     <li><a href="ShowStudent">学生信息</a></li>
    136     <li><a href="ShowTeacher">教师信息</a></li>
    137     <li><a href="ShowUser">用户信息</a></li>
    138     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    139     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    140     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    141     <li><a href="Update.jsp">修改信息</a></li>
    142     <li><a href="ShowClass">选课</a></li>
    143     <li><a href="HaveSelected">已选课</a>
    144     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    145     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    146     <li><a href="AddClass.jsp">添加课程</a></li>
    147     <li><a href="ShowTeaClas">自己的课程</a></li>
    148     <%} %>    
    149     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    150 </ul>
    151 </div>
    152 <div id="right">
    153 <form action="StudentIn">
    154 <table>
    155 <tr>
    156 
    157 <td>姓名:</td><td><input type="text" name="name" id="name"></td>
    158 </tr><tr>
    159 <td>学号:</td><td><input type="text" name="id" id="id"></td>
    160 </tr>
    161 <tr>
    162 <td>性别:</td><td><input type="text" name="sex" id="sex"></td>
    163 </tr>
    164 <tr>
    165 <td>班级:</td><td><input type="text" name="clas" id="clas"></td></tr>
    166 <tr>
    167 <td>学院:</td><td><input type="text" name="yard" id="yard"></td></tr>
    168 <tr>
    169 <td>密码:</td><td><input type="text" name="password" id="password"></td></tr>
    170 <tr><td colspan="2"><button type="submit" value="提 交">提交</button></td></tr>
    171 </table>
    172 </form>
    173 </div>
    174 </body>
    175 </html>
    StudentIn.jsp
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.SQLException;
     6 import java.sql.Statement;
     7 
     8 import javax.servlet.ServletException;
     9 import javax.servlet.annotation.WebServlet;
    10 import javax.servlet.http.HttpServlet;
    11 import javax.servlet.http.HttpServletRequest;
    12 import javax.servlet.http.HttpServletResponse;
    13 @WebServlet("/StudentIn")
    14 public class StudentIn extends HttpServlet {
    15     private static final long serialVersionUID = 1L;
    16     public StudentIn() {
    17         super();
    18         // TODO Auto-generated constructor stub
    19     }
    20     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    21         String name=request.getParameter("name");
    22         String userid=request.getParameter("id");
    23         int id=Integer.parseInt(userid);
    24         String sex=request.getParameter("sex");
    25         String clas=request.getParameter("clas");
    26         String yard=request.getParameter("yard");
    27         String password=request.getParameter("password");
    28         Link l=new Link();
    29         try {
    30             Connection con=l.lin("Class_Select");
    31             Statement stmt=con.createStatement();
    32             String s="insert into User_Student values ('"+id+"','"+name+"','"+sex+"','"+clas+"','"+yard+"','"+id+"','"+password+"')";
    33             stmt.executeUpdate(s);
    34             String s2="insert into userr values ('"+id+"','"+password+"','stu')";
    35             stmt.executeUpdate(s2);
    36             stmt.close();
    37             con.close();
    38         } catch (SQLException e) {
    39             e.printStackTrace();
    40         }
    41         request.getSession().setAttribute("message", "添加成功!");
    42         request.getRequestDispatcher("StudentIn.jsp").forward(request, response);
    43     }
    44     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    45         doGet(request, response);
    46     }
    47 
    48 }
    StudentIn.java
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 <!DOCTYPE html>
      5 <html>
      6 <head>
      7 <meta charset="UTF-8">
      8 <title>Document</title>
      9 <style type="text/css">
     10 
     11         #d1{
     12             text-align: center;
     13             padding-top: 40px;
     14             font-family: "微软雅黑";
     15             font-size: 40px;
     16             background-color: #DDDDDD;
     17             height: 100px;
     18         }
     19         div ul{
     20             vertical-align: top;
     21             list-style-type: none;
     22             margin: 0px;
     23             vertical-align: left;
     24             width: 200px;
     25             padding: 0px;
     26             border-top: 20px solid #F8A0E7;
     27             border-bottom :20px solid #F8A0E7;
     28         }
     29         .headd{
     30             font-family: "微软雅黑";
     31             lighting-color: red;
     32             font-size: 20px;
     33         }
     34         div li a{
     35             height: 80px;
     36             display: block;
     37             padding: 0px 0px 0px 0em;
     38             text-decoration: none;
     39             border-left: 20px solid pink;
     40         }
     41         div li a:link,div li a:visited{
     42             background-color: #F0F0F0;
     43             color: #461737;
     44         }
     45         div li a:hover{
     46             background-color: green;
     47             color: gray;
     48         }
     49         div li a:active{
     50             background-color: pink;
     51         }
     52         #left{
     53         float:left;
     54         }
     55         #right{
     56         height:400px;
     57         width:1100px;
     58         float:left;
     59         }
     60         #inp{
     61         float:left;
     62         height:400px;
     63         width:1202px;
     64         }
     65         .btn{
     66         float:left;
     67         }
     68           table
     69         {
     70             width:1100px;
     71             height:500px;
     72             border-collapse: collapse;
     73             margin: 0 auto;
     74             text-align: center;
     75         }
     76         table td, table th
     77         {
     78             border: 1px solid #cad9ea;
     79             color: #666;
     80             height: 30px;
     81         }
     82         table thead th
     83         {
     84             background-color: #CCE8EB;
     85             width: 100px;
     86         }
     87         table tr:nth-child(odd)
     88         {
     89             background: #fff;
     90         }
     91         table tr:nth-child(even)
     92         {
     93             background: #F5FAFA;
     94         }
     95                 
     96     button { /* 按钮美化 */
     97     width: 270px; /* 宽度 */
     98     height: 40px; /* 高度 */
     99     border-width: 0px; /* 边框宽度 */
    100     border-radius: 3px; /* 边框半径 */
    101     background: #1E90FF; /* 背景颜色 */
    102     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    103     outline: none; /* 不显示轮廓线 */
    104     font-family: Microsoft YaHei; /* 设置字体 */
    105     color: white; /* 字体颜色 */
    106     font-size: 17px; /* 字体大小 */
    107 }
    108     button:hover { /* 鼠标移入按钮范围时改变颜色 */
    109     background: #5599FF;
    110 
    111 </style>
    112 
    113     <%
    114     String message = (String) session.getAttribute("message");
    115     if (message != null) {
    116 %>
    117 <script type="text/javascript">
    118     alert("<%=message%>");
    119 </script>
    120 <%
    121     session.removeAttribute("message");
    122     }
    123 %>
    124 
    125 
    126 </head>
    127 <body onload="Onload()">
    128     <div id="d1">学生管理系统</div>
    129     <div id="left">
    130 <ul>
    131     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    132     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    133     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    134     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    135     <li><a href="AddUser.jsp">用户录入</a></li>
    136     <li><a href="ShowStudent">学生信息</a></li>
    137     <li><a href="ShowTeacher">教师信息</a></li>
    138     <li><a href="ShowUser">用户信息</a></li>
    139     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    140     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    141     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    142     <li><a href="Update.jsp">修改信息</a></li>
    143     <li><a href="ShowClass">选课</a></li>
    144     <li><a href="HaveSelected">已选课</a>
    145     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    146     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    147     <li><a href="AddClass.jsp">添加课程</a></li>
    148     <li><a href="ShowTeaClas">自己的课程</a></li>
    149     <%} %>    
    150     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    151 </ul>
    152 </div>
    153 <div id="right">
    154 <form action="TeacherIn">
    155 <table>
    156 <tr>
    157 
    158 <td>姓名:</td><td><input type="text" name="name" id="name"></td>
    159 </tr><tr>
    160 <td>工号:</td><td><input type="text" name="id" id="id"></td>
    161 </tr>
    162 <tr>
    163 <td>性别:</td><td><input type="text" name="sex" id="sex"></td>
    164 </tr>
    165 <tr>
    166 <td>学院:</td><td><input type="text" name="clas" id="clas"></td></tr>
    167 <tr>
    168 <td>职称:</td><td><input type="text" name="call" id="call"></td>
    169 </tr>
    170 <tr>
    171 <td>密码:</td><td><input type="text" name="password" id="password"></td></tr>
    172 <tr><td colspan="2"><button type="submit" value="提 交">提交</button></td></tr>
    173 </table>
    174 </form>
    175 </div>
    176 </body>
    177 </html>
    TeacherIn.jsp
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.SQLException;
     6 import java.sql.Statement;
     7 
     8 import javax.servlet.ServletException;
     9 import javax.servlet.annotation.WebServlet;
    10 import javax.servlet.http.HttpServlet;
    11 import javax.servlet.http.HttpServletRequest;
    12 import javax.servlet.http.HttpServletResponse;
    13 @WebServlet("/TeacherIn")
    14 public class TeacherIn extends HttpServlet {
    15     private static final long serialVersionUID = 1L;
    16     public TeacherIn() {
    17         super();
    18         // TODO Auto-generated constructor stub
    19     }
    20     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    21         String name=request.getParameter("name");
    22         String userid=request.getParameter("id");
    23         int id=Integer.parseInt(userid);
    24         String sex=request.getParameter("sex");
    25         String call=request.getParameter("call");
    26         String clas=request.getParameter("clas");
    27         String password=request.getParameter("password");
    28         Link l=new Link();
    29         try {
    30             Connection con=l.lin("Class_Select");
    31             Statement stmt=con.createStatement();
    32             String s="insert into User_Teacher values ("+id+",'"+name+"','"+sex+"','"+clas+"','"+call+"','"+password+"')";
    33             System.out.println(s);
    34             stmt.executeUpdate(s);
    35             String s2="insert into userr values ('"+id+"','"+password+"','tch')";
    36             stmt.executeUpdate(s2);
    37             stmt.close();
    38             con.close();
    39         } catch (SQLException e) {
    40             e.printStackTrace();
    41         }
    42         request.getSession().setAttribute("message", "添加成功!");
    43         request.getRequestDispatcher("TeacherIn.jsp").forward(request, response);
    44     }
    45     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    46         doGet(request, response);
    47     }
    48 
    49 }
    TeacherIn.java
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 <!DOCTYPE html>
      5 <html>
      6 <head>
      7 <meta charset="UTF-8">
      8 <title>Document</title>
      9 <style type="text/css">
     10         #d1{
     11             text-align: center;
     12             padding-top: 40px;
     13             font-family: "微软雅黑";
     14             font-size: 40px;
     15             background-color: #DDDDDD;
     16             height: 100px;
     17         }
     18         div ul{
     19             vertical-align: top;
     20             list-style-type: none;
     21             margin: 0px;
     22             vertical-align: left;
     23             width: 200px;
     24             padding: 0px;
     25             border-top: 20px solid #F8A0E7;
     26             border-bottom :20px solid #F8A0E7;
     27         }
     28         .headd{
     29             font-family: "微软雅黑";
     30             lighting-color: red;
     31             font-size: 20px;
     32         }
     33         div li a{
     34             height: 80px;
     35             display: block;
     36             padding: 0px 0px 0px 0em;
     37             text-decoration: none;
     38             border-left: 20px solid pink;
     39         }
     40         div li a:link,div li a:visited{
     41             background-color: #F0F0F0;
     42             color: #461737;
     43         }
     44         div li a:hover{
     45             background-color: green;
     46             color: gray;
     47         }
     48         div li a:active{
     49             background-color: pink;
     50         }
     51         #left{
     52         float:left;
     53         }
     54         #right{
     55         height:400px;
     56         width:1100px;
     57         float:left;
     58         }
     59         #inp{
     60         float:left;
     61         height:400px;
     62         width:1202px;
     63         }
     64         .btn{
     65         float:left;
     66         }
     67           table
     68         {
     69             width:1100px;
     70             height:500px;
     71             border-collapse: collapse;
     72             margin: 0 auto;
     73             text-align: center;
     74         }
     75         table td, table th
     76         {
     77             border: 1px solid #cad9ea;
     78             color: #666;
     79             height: 30px;
     80         }
     81         table thead th
     82         {
     83             background-color: #CCE8EB;
     84             width: 100px;
     85         }
     86         table tr:nth-child(odd)
     87         {
     88             background: #fff;
     89         }
     90         table tr:nth-child(even)
     91         {
     92             background: #F5FAFA;
     93         }
     94                 
     95     button { /* 按钮美化 */
     96     width: 270px; /* 宽度 */
     97     height: 40px; /* 高度 */
     98     border-width: 0px; /* 边框宽度 */
     99     border-radius: 3px; /* 边框半径 */
    100     background: #1E90FF; /* 背景颜色 */
    101     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    102     outline: none; /* 不显示轮廓线 */
    103     font-family: Microsoft YaHei; /* 设置字体 */
    104     color: white; /* 字体颜色 */
    105     font-size: 17px; /* 字体大小 */
    106 }
    107     button:hover { /* 鼠标移入按钮范围时改变颜色 */
    108     background: #5599FF;
    109     
    110 #chk {
    111     display: none;  /* 将原生的checkbox隐藏 */
    112 }
    113  
    114 /* label 模拟 “划动条” */
    115 #chk + label {  
    116     position: relative;
    117     display: inline-block;
    118     width: 60px;
    119     height: 20px;
    120     border-radius: 10px;
    121     background-color: #bbb;    
    122 }
    123  
    124 /* “label::before伪元素 模拟 “划块” */
    125 #sex + label:before {
    126     content: '';
    127     cursor: pointer;
    128     position: absolute;
    129     top: -5px;
    130     left: 0;
    131     z-index: 99;
    132     width: 30px;
    133     height: 30px;
    134     border-radius: 50%;
    135     background: #F7F4F4;
    136     box-shadow: 0 3px 1px rgba(0,0,0,0.05), 0 0px 1px rgba(0,0,0,0.3);
    137     -webkit-transition: all 0.1s ease-in;
    138     transition: all 0.1s ease-in;
    139 }
    140  
    141 /* checkbox选中状态时,“划动条”的样式 */
    142 #sex:checked + label {
    143     background: #aabbfd;    
    144 }
    145  
    146 /* checkbox选中状态时,“划块”的样式 */
    147 #sex:checked + label:before {
    148     content: '';
    149     position: absolute;
    150     left: 30px;
    151     background-color: #4ea5dd;    
    152 </style>
    153 <%
    154     String message = (String) session.getAttribute("message");
    155     if (message != null) {
    156 %>
    157 <script type="text/javascript">
    158     alert("<%=message%>");
    159 </script>
    160 <%
    161     session.removeAttribute("message");
    162     }
    163 %>
    164 </head>
    165 <body>
    166     <div id="d1">学生信息管理系统</div>
    167     <div id="left">
    168 <ul>
    169     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    170     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    171     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    172     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    173     <li><a href="AddUser.jsp">用户录入</a></li>
    174     <li><a href="ShowStudent">学生信息</a></li>
    175     <li><a href="ShowTeacher">教师信息</a></li>
    176     <li><a href="ShowUser">用户信息</a></li>
    177     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    178     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    179     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    180     <li><a href="Update.jsp">修改信息</a></li>
    181     <li><a href="ShowClass">选课</a></li>
    182     <li><a href="HaveSelected">已选课</a>
    183     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    184     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    185     <li><a href="AddClass.jsp">添加课程</a></li>
    186     <li><a href="ShowTeaClas">自己的课程</a></li>
    187     <%} %>    
    188     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    189 </ul>
    190 </div>
    191 <div id="right">
    192 <form action="UserIn">
    193 <table>
    194 <tr>
    195 <td>账号:</td><td><input type="text" name="username" id="username"></td></tr>
    196 <tr><td>密码:</td><td><input type="text" name="password" id="password"></td></tr>
    197 <tr><td>用户类型:</td><td><input type="text" name="usertype" id="usertype"></td></tr>
    198 <tr><td colspan="2"><button type="submit" value="提 交">提交</button></td></tr>
    199 </table>
    200 </form>
    201 </div>
    202 </body>
    203 </html>
    AddUser.jsp
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 
     9 import javax.servlet.ServletException;
    10 import javax.servlet.annotation.WebServlet;
    11 import javax.servlet.http.HttpServlet;
    12 import javax.servlet.http.HttpServletRequest;
    13 import javax.servlet.http.HttpServletResponse;
    14 
    15 @WebServlet("/UserIn")
    16 public class UserIn extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public UserIn() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response)
    22             throws ServletException, IOException {
    23         String username=request.getParameter("username");
    24         String password = request.getParameter("password");
    25         String type=request.getParameter("usertype");
    26         int flag = 0;
    27         Link l = new Link();
    28         try {
    29             Connection con = l.lin("Class_Select");
    30             Statement stmt = con.createStatement();
    31             String s0 = "select * from userr";
    32             ResultSet rsst = stmt.executeQuery(s0);
    33             while(rsst.next()) {
    34                 if(username.equals(rsst.getString("username"))) {
    35                     flag=1;
    36                 }
    37             }
    38             if(flag==0) {
    39                 String s="insert into userr values('"+username+"','"+password+"','"+type+"')";
    40                 stmt.executeUpdate(s);
    41             }
    42             stmt.close();
    43             rsst.close();
    44             con.close();
    45         } catch (SQLException e) {
    46             e.printStackTrace();
    47         }
    48         if(flag==0) {
    49         request.getSession().setAttribute("message", "录入成功!");
    50         }else {
    51             request.getSession().setAttribute("message", "用户名已存在!请重新录入!");
    52         }
    53         
    54         request.getRequestDispatcher("AddUser.jsp").forward(request, response);
    55         response.getWriter().append("Served at: ").append(request.getContextPath());
    56     }
    57 
    58     protected void doPost(HttpServletRequest request, HttpServletResponse response)
    59             throws ServletException, IOException {
    60         doGet(request, response);
    61     }
    62 
    63 }
    UserIn.java

    学生信息页面:

     从学生表中读取学生信息,存储到studentBean中传到jsp

    可对学生信息进行修改和删除:

    修改:点击修改进入修改界面

     除学号外都可进行修改:

     

     

     修改完成后跳回学生信息界面

    删除:

     

     

     删除成功后跳回学生信息界面。

    学生信息界面同时提供简单查询选项,可按班级和姓名进行查询:

     

     查询成功后显示学生信息,查询失败显示查无此人并跳回学生信息界面

    显示信息:

     1 package p1;
     2 
     3 public class StudentBean {
     4 private String id,name,sex,yard,clas;
     5 public String getId() {
     6     return id;
     7 }
     8 
     9 public void setId(String id) {
    10     this.id = id;
    11 }
    12 
    13 public String getName() {
    14     return name;
    15 }
    16 
    17 public void setName(String name) {
    18     this.name = name;
    19 }
    20 
    21 public String getSex() {
    22     return sex;
    23 }
    24 
    25 public void setSex(String sex) {
    26     this.sex = sex;
    27 }
    28 
    29 public String getYard() {
    30     return yard;
    31 }
    32 
    33 public void setYard(String yard) {
    34     this.yard = yard;
    35 }
    36 
    37 public String getClas() {
    38     return clas;
    39 }
    40 
    41 public void setClas(String clas) {
    42     this.clas = clas;
    43 }
    44 
    45 }
    StudentBean.java
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/ShowStudent")
    16 public class ShowStudent extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public ShowStudent() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         ArrayList<StudentBean> arr=new ArrayList<StudentBean>();
    23         Link l=new Link();
    24         try {
    25             Connection con=l.lin("Class_Select");
    26             Statement stmt=con.createStatement();
    27             String s="select * from User_Student";
    28             ResultSet rsst=stmt.executeQuery(s);
    29             while(rsst.next()) {
    30                 StudentBean ub=new StudentBean();
    31                 ub.setId(rsst.getString(1));
    32                 ub.setName(rsst.getString(2));
    33                 ub.setSex(rsst.getString(3));
    34                 ub.setYard(rsst.getString(4));
    35                 ub.setClas(rsst.getString(5));
    36                 arr.add(ub);
    37             }
    38         } catch (SQLException e) {
    39             e.printStackTrace();
    40         }
    41         request.setAttribute("list", arr);
    42         request.getRequestDispatcher("ShowStudent.jsp").forward(request, response);
    43     }
    44     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    45         doGet(request, response);
    46     }
    47 
    48 }
    ShowStudent.java
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 
      5 <!DOCTYPE html>
      6 <html>
      7 <head>
      8 <meta charset="UTF-8">
      9 <title>Document</title>
     10 <style type="text/css">
     11 #d1 {
     12     text-align: center;
     13     padding-top: 40px;
     14     font-family: "微软雅黑";
     15     font-size: 40px;
     16     background-color: #DDDDDD;
     17     height: 100px;
     18 }
     19 
     20 div ul {
     21     vertical-align: top;
     22     list-style-type: none;
     23     margin: 0px;
     24     vertical-align: left;
     25     width: 200px;
     26     padding: 0px;
     27     border-top: 20px solid #F8A0E7;
     28     border-bottom: 20px solid #F8A0E7;
     29 }
     30 
     31 .headd {
     32     font-family: "微软雅黑";
     33     lighting-color: red;
     34     font-size: 20px;
     35 }
     36 
     37 div li a {
     38     height: 80px;
     39     display: block;
     40     padding: 0px 0px 0px 0em;
     41     text-decoration: none;
     42     border-left: 20px solid pink;
     43 }
     44 
     45 div li a:link, div li a:visited {
     46     background-color: #F0F0F0;
     47     color: #461737;
     48 }
     49 
     50 div li a:hover {
     51     background-color: green;
     52     color: gray;
     53 }
     54 
     55 div li a:active {
     56     background-color: pink;
     57 }
     58 
     59 #left {
     60     float: left;
     61 }
     62 
     63 #right {
     64     height: 400px;
     65     width: 1100px;
     66     float: left;
     67 }
     68 
     69 #inp {
     70     float: left;
     71     height: 400px;
     72     width: 1202px;
     73 }
     74 
     75 .btn {
     76     float: left;
     77 }
     78 
     79 table {
     80     width: 1300px;
     81     height: 500px;
     82     border-collapse: collapse;
     83     margin: 0 auto;
     84     text-align: center;
     85 }
     86 
     87 table td, table th {
     88     border: 1px solid #cad9ea;
     89     color: #666;
     90     height: 30px;
     91 }
     92 
     93 table thead th {
     94     background-color: #CCE8EB;
     95     width: 100px;
     96 }
     97 
     98 table tr:nth-child(odd) {
     99     background: #fff;
    100 }
    101 
    102 table tr:nth-child(even) {
    103     background: #F5FAFA;
    104 }
    105 
    106 button { /* 按钮美化 */
    107     width: 170px; /* 宽度 */
    108     height: 40px; /* 高度 */
    109     border-width: 0px; /* 边框宽度 */
    110     border-radius: 3px; /* 边框半径 */
    111     background: #1E90FF; /* 背景颜色 */
    112     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    113     outline: none; /* 不显示轮廓线 */
    114     font-family: Microsoft YaHei; /* 设置字体 */
    115     color: white; /* 字体颜色 */
    116     font-size: 17px; /* 字体大小 */
    117 }
    118 
    119 button:hover { /* 鼠标移入按钮范围时改变颜色 */
    120     background: #5599FF;
    121 }
    122 </style>
    123 <%
    124     String message = (String) session.getAttribute("message");
    125     if (message != null) {
    126 %>
    127 <script type="text/javascript">
    128     alert("<%=message%>");
    129     </script>
    130 <%
    131     session.removeAttribute("message");
    132     }
    133 %>
    134 <script type="text/javascript">
    135 function Update(id){
    136     window.location.href="ShowMySession?id="+id;
    137 }
    138 function Borrow(id){
    139     var sen=confirm("确认删除?");
    140     if(sen==true)
    141     window.location.href="DeleteStudent?id="+id;
    142 }
    143 </script>
    144 </head>
    145 <body onload="Onload()">
    146     <div id="d1">学生信息管理系统</div>
    147     <div id="left">
    148 <ul>
    149     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    150     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    151     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    152     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    153     <li><a href="AddUser.jsp">用户录入</a></li>
    154     <li><a href="ShowStudent">学生信息</a></li>
    155     <li><a href="ShowTeacher">教师信息</a></li>
    156     <li><a href="ShowUser">用户信息</a></li>
    157     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    158     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    159     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    160     <li><a href="Update.jsp">修改信息</a></li>
    161     <li><a href="ShowClass">选课</a></li>
    162     <li><a href="HaveSelected">已选课</a>
    163     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    164     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    165     <li><a href="AddClass.jsp">添加课程</a></li>
    166     <li><a href="ShowTeaClas">自己的课程</a></li>
    167     <%} %>    
    168     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    169 </ul>
    170     </div>
    171     <div id="right">
    172         <table>
    173             <tr>
    174                 
    175                 <td>按姓名查找:</td>
    176                 <form action="SearchByName">
    177                 <td><input type="text" name="name"></td>
    178                 <td><button>查询</button></td>
    179                 </form>
    180                 <td>按班级查找:</td>
    181                 <form action="SearchByClas">
    182                 <td><input type="text" name="clas"></td>
    183                 <td><button>查询</button></td></form>
    184         
    185             </tr>
    186             <c:forEach items="${list}" var="list">
    187                 <tr>
    188                     <td>学院:${list.yard}</td>
    189                     <td>班级:${list.clas}</td>
    190                     <td>姓名:${list.name}</td>
    191                     <td>性别:${list.sex}</td>
    192                     <td>学号:${list.id}</td>
    193                     <td><button onclick="Update(${list.id})">修改</button></td>
    194                     <td><button onclick="Borrow(${list.id})">删除</button></td>
    195                 </tr>
    196             </c:forEach>
    197         </table>
    198     </div>
    199 </body>
    200 </html>
    ShowStudent.jsp

    修改:

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/ShowMySession")
    16 public class ShowMySession extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public ShowMySession() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         ArrayList<StudentBean> arr=new ArrayList<StudentBean>();
    23         String id=request.getParameter("id");
    24         System.out.println(id);
    25         Link l=new Link();
    26         try {
    27             Connection con=l.lin("Class_Select");
    28             Statement stmt=con.createStatement();
    29             String s="select * from User_Student where id='"+id+"'";
    30             ResultSet rsst=stmt.executeQuery(s);
    31             while(rsst.next()) {
    32                 StudentBean ub=new StudentBean();
    33                 ub.setId(rsst.getString(1));
    34                 ub.setName(rsst.getString(2));
    35                 ub.setSex(rsst.getString(3));
    36                 ub.setYard(rsst.getString(4));
    37                 ub.setClas(rsst.getString(5));
    38                 arr.add(ub);
    39             }
    40         } catch (SQLException e) {
    41             e.printStackTrace();
    42         }
    43         request.setAttribute("list", arr);
    44         request.getRequestDispatcher("ShowMySession.jsp").forward(request, response);
    45     }
    46     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    47         doGet(request, response);
    48     }
    49 
    50 }
    ShowMySession.java
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 
      5 <!DOCTYPE html>
      6 <html>
      7 <head>
      8 <meta charset="UTF-8">
      9 <title>Document</title>
     10 <style type="text/css">
     11 #d1 {
     12     text-align: center;
     13     padding-top: 40px;
     14     font-family: "微软雅黑";
     15     font-size: 40px;
     16     background-color: #DDDDDD;
     17     height: 100px;
     18 }
     19 
     20 div ul {
     21     vertical-align: top;
     22     list-style-type: none;
     23     margin: 0px;
     24     vertical-align: left;
     25     width: 200px;
     26     padding: 0px;
     27     border-top: 20px solid #F8A0E7;
     28     border-bottom: 20px solid #F8A0E7;
     29 }
     30 
     31 .headd {
     32     font-family: "微软雅黑";
     33     lighting-color: red;
     34     font-size: 20px;
     35 }
     36 
     37 div li a {
     38     height: 80px;
     39     display: block;
     40     padding: 0px 0px 0px 0em;
     41     text-decoration: none;
     42     border-left: 20px solid pink;
     43 }
     44 
     45 div li a:link, div li a:visited {
     46     background-color: #F0F0F0;
     47     color: #461737;
     48 }
     49 
     50 div li a:hover {
     51     background-color: green;
     52     color: gray;
     53 }
     54 
     55 div li a:active {
     56     background-color: pink;
     57 }
     58 
     59 #left {
     60     float: left;
     61 }
     62 
     63 #right {
     64     height: 400px;
     65     width: 1100px;
     66     float: left;
     67 }
     68 
     69 #inp {
     70     float: left;
     71     height: 400px;
     72     width: 1202px;
     73 }
     74 
     75 .btn {
     76     float: left;
     77 }
     78 
     79 table {
     80     width: 1300px;
     81     height: 500px;
     82     border-collapse: collapse;
     83     margin: 0 auto;
     84     text-align: center;
     85 }
     86 
     87 table td, table th {
     88     border: 1px solid #cad9ea;
     89     color: #666;
     90     height: 30px;
     91 }
     92 
     93 table thead th {
     94     background-color: #CCE8EB;
     95     width: 100px;
     96 }
     97 
     98 table tr:nth-child(odd) {
     99     background: #fff;
    100 }
    101 
    102 table tr:nth-child(even) {
    103     background: #F5FAFA;
    104 }
    105 
    106 button { /* 按钮美化 */
    107     width: 270px; /* 宽度 */
    108     height: 40px; /* 高度 */
    109     border-width: 0px; /* 边框宽度 */
    110     border-radius: 3px; /* 边框半径 */
    111     background: #1E90FF; /* 背景颜色 */
    112     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    113     outline: none; /* 不显示轮廓线 */
    114     font-family: Microsoft YaHei; /* 设置字体 */
    115     color: white; /* 字体颜色 */
    116     font-size: 17px; /* 字体大小 */
    117 }
    118 
    119 button:hover { /* 鼠标移入按钮范围时改变颜色 */
    120     background: #5599FF;
    121 }
    122 </style>
    123 <%
    124     String message = (String) session.getAttribute("message");
    125     if (message != null) {
    126 %>
    127 <script type="text/javascript">
    128     alert("<%=message%>");
    129     </script>
    130 <%
    131     session.removeAttribute("message");
    132     }
    133 %>
    134 <script type="text/javascript">
    135 function UpdateYard(id){
    136     var word=prompt("请输入修改后的结果:");
    137     word=encodeURIComponent(word);
    138     var sentence=confirm("是否确认修改!");
    139     if(sentence==true)
    140     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=yard";
    141 }
    142 function UpdateName(id){
    143     var word=prompt("请输入修改后的结果:");
    144     var sentence=confirm("是否确认修改!");
    145     word=encodeURIComponent(word);
    146     if(sentence==true)
    147     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=name";
    148 }
    149 function UpdateSex(id){
    150     var word=prompt("请输入修改后的结果:");
    151     var sentence=confirm("是否确认修改!");
    152     word=encodeURIComponent(word);
    153     if(sentence==true)
    154     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=sex";
    155 }
    156 function UpdateClas(id){
    157     var word=prompt("请输入修改后的结果:");
    158     var sentence=confirm("是否确认修改!");
    159     word=encodeURIComponent(word);
    160     if(sentence==true)
    161     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=clas";
    162 }
    163 
    164 </script>
    165 </head>
    166 <body onload="Onload()">
    167     <div id="d1">学生信息管理系统</div>
    168     <div id="left">
    169 <ul>
    170     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    171     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    172     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    173     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    174     <li><a href="AddUser.jsp">用户录入</a></li>
    175     <li><a href="ShowStudent">学生信息</a></li>
    176     <li><a href="ShowTeacher">教师信息</a></li>
    177     <li><a href="ShowUser">用户信息</a></li>
    178     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    179     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    180     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    181     <li><a href="ShowClass">选课</a></li>
    182     <li><a href="HaveSelected">已选课</a>
    183     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    184     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    185     <li><a href="AddClass.jsp">添加课程</a></li>
    186     <li><a href="ShowTeaClas">自己的课程</a></li>
    187     <%} %>    
    188     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    189 </ul>
    190     </div>
    191     <div id="right">
    192         <table>
    193             <c:forEach items="${list}" var="list">
    194                 <tr>
    195                     <td>学院:${list.yard}</td>
    196                     <%if(session.getAttribute("usertype").equals("root")){ %>
    197                     <td><button onclick="UpdateYard(${list.id})">修改</button></td><%} %>
    198                 </tr><tr>
    199                     <td>班级:${list.clas}</td>
    200                     <%if(session.getAttribute("usertype").equals("root")){ %>
    201                     <td><button onclick="UpdateClas(${list.id})">修改</button></td><%} %>
    202                 </tr><tr>
    203                     <td>姓名:${list.name}</td>
    204                             <%if(session.getAttribute("usertype").equals("root")){ %>
    205                     <td><button onclick="UpdateName(${list.id})">修改</button></td><%} %>
    206                 </tr><tr>
    207                     <td>性别:${list.sex}</td>
    208                             <%if(session.getAttribute("usertype").equals("root")){ %>
    209                     <td><button onclick="UpdateSex(${list.id})">修改</button></td><%} %>
    210                 </tr><tr>
    211                     <td>学号:${list.id}</td>
    212                 </tr>
    213             </c:forEach>
    214         </table>
    215     </div>
    216 </body>
    217 </html>
    ShowMySession.jsp
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.SQLException;
     6 import java.sql.Statement;
     7 
     8 import javax.servlet.ServletException;
     9 import javax.servlet.annotation.WebServlet;
    10 import javax.servlet.http.HttpServlet;
    11 import javax.servlet.http.HttpServletRequest;
    12 import javax.servlet.http.HttpServletResponse;
    13 @WebServlet("/UpdateStudent")
    14 public class UpdateStudent extends HttpServlet {
    15     private static final long serialVersionUID = 1L;
    16     public UpdateStudent() {
    17         super();
    18     }
    19     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    20         String type=request.getParameter("type");
    21         String word=request.getParameter("word");
    22         String id=request.getParameter("id");
    23         Link l=new Link();
    24         try {
    25             Connection con=l.lin("Class_Select");
    26             Statement stmt=con.createStatement();
    27             String s="update User_Student set "+type+"='"+word+"' where id='"+id+"'";
    28             stmt.executeUpdate(s);
    29             stmt.close();
    30             con.close();
    31         } catch (SQLException e) {
    32             e.printStackTrace();
    33         }
    34         request.getSession().setAttribute("message", "修改成功!");
    35         request.getRequestDispatcher("ShowStudent").forward(request, response);
    36     }
    37     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    38         // TODO Auto-generated method stub
    39         doGet(request, response);
    40     }
    41 
    42 }
    UpdateStudent.java

    删除:

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.SQLException;
     6 import java.sql.Statement;
     7 
     8 import javax.servlet.ServletException;
     9 import javax.servlet.annotation.WebServlet;
    10 import javax.servlet.http.HttpServlet;
    11 import javax.servlet.http.HttpServletRequest;
    12 import javax.servlet.http.HttpServletResponse;
    13 @WebServlet("/DeleteStudent")
    14 public class DeleteStudent extends HttpServlet {
    15     private static final long serialVersionUID = 1L;
    16     public DeleteStudent() {
    17         super();
    18     }
    19     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    20         String id=request.getParameter("id");
    21         Link l=new Link();
    22         try {
    23             Connection con=l.lin("Class_Select");
    24             Statement stmt=con.createStatement();
    25             String s="delete User_Student where id='"+id+"'";
    26             stmt.executeUpdate(s);
    27         } catch (SQLException e) {
    28             e.printStackTrace();
    29         }
    30         request.getSession().setAttribute("message", "删除成功!");
    31         request.getRequestDispatcher("ShowStudent").forward(request, response);
    32     }
    33 
    34     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    35         doGet(request, response);
    36     }
    37 
    38 }
    DeleteStudent.java

    查询:

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/SearchByName")
    16 public class SearchByName extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public SearchByName() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         String name=request.getParameter("name");
    23         ArrayList<StudentBean> list=new ArrayList<>();
    24         int flag=0;
    25         System.out.println(name);
    26         if(name!=""&&name!=null) {
    27             Link l=new Link();
    28             try {
    29                 Connection con=l.lin("Class_Select");
    30                 Statement stmt=con.createStatement();
    31                 ResultSet rsst=stmt.executeQuery("select * from User_Student where name='"+name+"'");
    32                 while(rsst.next()) {
    33                     StudentBean st=new StudentBean();
    34                     st.setId(rsst.getString(1));
    35                     st.setName(rsst.getString(2));
    36                     st.setSex(rsst.getString(3));
    37                     st.setYard(rsst.getString(4));
    38                     st.setClas(rsst.getString(5));
    39                     list.add(st);
    40                     flag=1;
    41                 }
    42             } catch (SQLException e) {
    43                 // TODO Auto-generated catch block
    44                 e.printStackTrace();
    45             }
    46 
    47     }
    48         if(flag==0) {
    49             System.out.println(1111111);
    50             request.getSession().setAttribute("message", "查无此人!");
    51             request.getRequestDispatcher("ShowStudent").forward(request,response);
    52         }else {
    53             request.getSession().setAttribute("list", list);
    54     request.getRequestDispatcher("ShowStudent.jsp").forward(request,response);
    55         }
    56     }
    57     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    58         doGet(request, response);
    59     }
    60 
    61 }
    SearchByName.java
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/SearchByClas")
    16 public class SearchByClas extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public SearchByClas() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         String clas=request.getParameter("clas");
    23         ArrayList<StudentBean> list=new ArrayList<>();
    24         int flag=0;
    25         if(clas!=""&&clas!=null) {
    26             Link l=new Link();
    27             try {
    28                 Connection con=l.lin("Class_Select");
    29                 Statement stmt=con.createStatement();
    30                 ResultSet rsst=stmt.executeQuery("select * from User_Student where clas='"+clas+"'");
    31                 while(rsst.next()) {
    32                     StudentBean st=new StudentBean();
    33                     st.setId(rsst.getString(1));
    34                     st.setName(rsst.getString(2));
    35                     st.setSex(rsst.getString(3));
    36                     st.setYard(rsst.getString(4));
    37                     st.setClas(rsst.getString(5));
    38                     list.add(st);
    39                     flag=1;
    40                 }
    41             } catch (SQLException e) {
    42                 // TODO Auto-generated catch block
    43                 e.printStackTrace();
    44             }
    45 
    46     }
    47         if(flag==0) {
    48             System.out.println(1111111);
    49             request.getSession().setAttribute("message", "查无此班!");
    50             request.getRequestDispatcher("ShowStudent").forward(request,response);
    51         }else {
    52             request.getSession().setAttribute("list", list);
    53             System.out.println(1);
    54             request.getRequestDispatcher("ShowStudent.jsp").forward(request,response);
    55         }
    56     }
    57     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    58         doGet(request, response);
    59     }
    60 
    61 }
    SearchByClas.java

    教师信息界面:

    从教师表中读取教师信息存储到TeacherBean中,传输到jsp显示,大体同学生信息功能页相似

     显示教师信息:

     1 package p1;
     2 
     3 public class TeacherBean {
     4     private String sex,name,yard,call,id;
     5     public String getId() {
     6         return id;
     7     }
     8     public void setId(String id) {
     9         this.id = id;
    10     }
    11     public String getSex() {
    12         return sex;
    13     }
    14     public void setSex(String sex) {
    15         this.sex = sex;
    16     }
    17     public String getName() {
    18         return name;
    19     }
    20     public void setName(String name) {
    21         this.name = name;
    22     }
    23     public String getYard() {
    24         return yard;
    25     }
    26     public void setYard(String yard) {
    27         this.yard = yard;
    28     }
    29     public String getCall() {
    30         return call;
    31     }
    32     public void setCall(String call) {
    33         this.call = call;
    34     }
    35 }
    TeacherBean
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/ShowTeacher")
    16 public class ShowTeacher extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public ShowTeacher() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         ArrayList<TeacherBean> arr=new ArrayList<TeacherBean>();
    23         Link l=new Link();
    24         try {
    25             Connection con=l.lin("Class_Select");
    26             Statement stmt=con.createStatement();
    27             String s="select * from User_Teacher";
    28             ResultSet rsst=stmt.executeQuery(s);
    29             while(rsst.next()) {
    30                 TeacherBean ub=new TeacherBean();
    31                 ub.setId(rsst.getString(1));
    32                 ub.setName(rsst.getString(2));
    33                 ub.setSex(rsst.getString(3));
    34                 ub.setYard(rsst.getString(4));
    35                 ub.setCall(rsst.getString(5));
    36                 arr.add(ub);
    37             }
    38         } catch (SQLException e) {
    39             e.printStackTrace();
    40         }
    41         request.setAttribute("list", arr);
    42         request.getRequestDispatcher("ShowTeacher.jsp").forward(request, response);
    43     }
    44     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    45         doGet(request, response);
    46     }
    47 
    48 }
    ShowTeacher.java
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 
      5 <!DOCTYPE html>
      6 <html>
      7 <head>
      8 <meta charset="UTF-8">
      9 <title>Document</title>
     10 <style type="text/css">
     11 #d1 {
     12     text-align: center;
     13     padding-top: 40px;
     14     font-family: "微软雅黑";
     15     font-size: 40px;
     16     background-color: #DDDDDD;
     17     height: 100px;
     18 }
     19 
     20 div ul {
     21     vertical-align: top;
     22     list-style-type: none;
     23     margin: 0px;
     24     vertical-align: left;
     25     width: 200px;
     26     padding: 0px;
     27     border-top: 20px solid #F8A0E7;
     28     border-bottom: 20px solid #F8A0E7;
     29 }
     30 
     31 .headd {
     32     font-family: "微软雅黑";
     33     lighting-color: red;
     34     font-size: 20px;
     35 }
     36 
     37 div li a {
     38     height: 80px;
     39     display: block;
     40     padding: 0px 0px 0px 0em;
     41     text-decoration: none;
     42     border-left: 20px solid pink;
     43 }
     44 
     45 div li a:link, div li a:visited {
     46     background-color: #F0F0F0;
     47     color: #461737;
     48 }
     49 
     50 div li a:hover {
     51     background-color: green;
     52     color: gray;
     53 }
     54 
     55 div li a:active {
     56     background-color: pink;
     57 }
     58 
     59 #left {
     60     float: left;
     61 }
     62 
     63 #right {
     64     height: 400px;
     65     width: 1100px;
     66     float: left;
     67 }
     68 
     69 #inp {
     70     float: left;
     71     height: 400px;
     72     width: 1202px;
     73 }
     74 
     75 .btn {
     76     float: left;
     77 }
     78 
     79 table {
     80     width: 1300px;
     81     height: 500px;
     82     border-collapse: collapse;
     83     margin: 0 auto;
     84     text-align: center;
     85 }
     86 
     87 table td, table th {
     88     border: 1px solid #cad9ea;
     89     color: #666;
     90     height: 30px;
     91 }
     92 
     93 table thead th {
     94     background-color: #CCE8EB;
     95     width: 100px;
     96 }
     97 
     98 table tr:nth-child(odd) {
     99     background: #fff;
    100 }
    101 
    102 table tr:nth-child(even) {
    103     background: #F5FAFA;
    104 }
    105 
    106 button { /* 按钮美化 */
    107     width: 170px; /* 宽度 */
    108     height: 40px; /* 高度 */
    109     border-width: 0px; /* 边框宽度 */
    110     border-radius: 3px; /* 边框半径 */
    111     background: #1E90FF; /* 背景颜色 */
    112     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    113     outline: none; /* 不显示轮廓线 */
    114     font-family: Microsoft YaHei; /* 设置字体 */
    115     color: white; /* 字体颜色 */
    116     font-size: 17px; /* 字体大小 */
    117 }
    118 
    119 button:hover { /* 鼠标移入按钮范围时改变颜色 */
    120     background: #5599FF;
    121 }
    122 </style>
    123 <%
    124     String message = (String) session.getAttribute("message");
    125     if (message != null) {
    126 %>
    127 <script type="text/javascript">
    128     alert("<%=message%>");
    129     </script>
    130 <%
    131     session.removeAttribute("message");
    132     }
    133 %>
    134 <script type="text/javascript">
    135 function Update(id){
    136     window.location.href="ShowTeaSession?id="+id;
    137 }
    138 function Borrow(id){
    139     var sen=confirm("确认删除?");
    140     if(sen==true)
    141     window.location.href="DeleteTeacher?id="+id;
    142 }
    143 </script>
    144 </head>
    145 <body onload="Onload()">
    146     <div id="d1">学生信息管理系统</div>
    147     <div id="left">
    148 <ul>
    149     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    150     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    151     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    152     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    153     <li><a href="AddUser.jsp">用户录入</a></li>
    154     <li><a href="ShowStudent">学生信息</a></li>
    155     <li><a href="ShowTeacher">教师信息</a></li>
    156     <li><a href="ShowUser">用户信息</a></li>
    157     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    158     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    159     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    160     <li><a href="Update.jsp">修改信息</a></li>
    161     <li><a href="ShowClass">选课</a></li>
    162     <li><a href="HaveSelected">已选课</a>
    163     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    164     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    165     <li><a href="AddClass.jsp">添加课程</a></li>
    166     <li><a href="ShowTeaClas">自己的课程</a></li>
    167     <%} %>    
    168     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    169 </ul>
    170     </div>
    171     <div id="right">
    172         <table>
    173             <tr>
    174                 
    175                 <td>按姓名查找:</td>
    176                 <form action="SearchTeaByName">
    177                 <td><input type="text" name="name"></td>
    178                 <td><button>查询</button></td>
    179                 </form>
    180                 <td>按学院查找:</td>
    181                 <form action="SearchTeaByClas">
    182                 <td><input type="text" name="clas"></td>
    183                 <td><button>查询</button></td></form>
    184         
    185             </tr>
    186             <c:forEach items="${list}" var="list">
    187                 <tr>    
    188                     <td>姓名:${list.name}</td>
    189                     <td>性别:${list.sex}</td>
    190                     <td>工号:${list.id}</td>
    191                     <td>学院:${list.yard}</td>
    192                     <td>职称:${list.call}</td>
    193                     <td><button onclick="Update(${list.id})">修改</button></td>
    194                     <td><button onclick="Borrow(${list.id})">删除</button></td>
    195                 </tr>
    196             </c:forEach>
    197         </table>
    198     </div>
    199 </body>
    200 </html>
    ShowTeacher.jsp

    显示教师详细信息:

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/ShowTeaSession")
    16 public class ShowTeaSession extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public ShowTeaSession() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         Link l=new Link();
    23         String id=request.getParameter("id");
    24         ArrayList<TeacherBean> list=new ArrayList<TeacherBean>();
    25         try {
    26             Connection con=l.lin("Class_Select");
    27             Statement stmt=con.createStatement();
    28             String s="select * from User_Teacher where id="+id;
    29             ResultSet rsst=stmt.executeQuery(s);
    30             while(rsst.next()) {
    31                 TeacherBean bk=new TeacherBean();
    32                 bk.setId(rsst.getString("id"));
    33                 bk.setName(rsst.getString("name"));
    34                 bk.setSex(rsst.getString("sex"));
    35                 bk.setYard(rsst.getString("yard"));
    36                 bk.setCall(rsst.getString("call"));
    37                 list.add(bk);
    38             }
    39             stmt.close();
    40             rsst.close();
    41             con.close();
    42         } catch (SQLException e) {
    43             // TODO Auto-generated catch block
    44             e.printStackTrace();
    45         }
    46         request.setAttribute("list", list);
    47         request.getRequestDispatcher("TeaShowMySession.jsp").forward(request, response);
    48     }
    49     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    50         // TODO Auto-generated method stub
    51         doGet(request, response);
    52     }
    53 
    54 }
    ShowTeaSession
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 
      5 <!DOCTYPE html>
      6 <html>
      7 <head>
      8 <meta charset="UTF-8">
      9 <title>Document</title>
     10 <style type="text/css">
     11 #d1 {
     12     text-align: center;
     13     padding-top: 40px;
     14     font-family: "微软雅黑";
     15     font-size: 40px;
     16     background-color: #DDDDDD;
     17     height: 100px;
     18 }
     19 
     20 div ul {
     21     vertical-align: top;
     22     list-style-type: none;
     23     margin: 0px;
     24     vertical-align: left;
     25     width: 200px;
     26     padding: 0px;
     27     border-top: 20px solid #F8A0E7;
     28     border-bottom: 20px solid #F8A0E7;
     29 }
     30 
     31 .headd {
     32     font-family: "微软雅黑";
     33     lighting-color: red;
     34     font-size: 20px;
     35 }
     36 
     37 div li a {
     38     height: 80px;
     39     display: block;
     40     padding: 0px 0px 0px 0em;
     41     text-decoration: none;
     42     border-left: 20px solid pink;
     43 }
     44 
     45 div li a:link, div li a:visited {
     46     background-color: #F0F0F0;
     47     color: #461737;
     48 }
     49 
     50 div li a:hover {
     51     background-color: green;
     52     color: gray;
     53 }
     54 
     55 div li a:active {
     56     background-color: pink;
     57 }
     58 
     59 #left {
     60     float: left;
     61 }
     62 
     63 #right {
     64     height: 400px;
     65     width: 1100px;
     66     float: left;
     67 }
     68 
     69 #inp {
     70     float: left;
     71     height: 400px;
     72     width: 1202px;
     73 }
     74 
     75 .btn {
     76     float: left;
     77 }
     78 
     79 table {
     80     width: 1300px;
     81     height: 500px;
     82     border-collapse: collapse;
     83     margin: 0 auto;
     84     text-align: center;
     85 }
     86 
     87 table td, table th {
     88     border: 1px solid #cad9ea;
     89     color: #666;
     90     height: 30px;
     91 }
     92 
     93 table thead th {
     94     background-color: #CCE8EB;
     95     width: 100px;
     96 }
     97 
     98 table tr:nth-child(odd) {
     99     background: #fff;
    100 }
    101 
    102 table tr:nth-child(even) {
    103     background: #F5FAFA;
    104 }
    105 
    106 button { /* 按钮美化 */
    107     width: 270px; /* 宽度 */
    108     height: 40px; /* 高度 */
    109     border-width: 0px; /* 边框宽度 */
    110     border-radius: 3px; /* 边框半径 */
    111     background: #1E90FF; /* 背景颜色 */
    112     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    113     outline: none; /* 不显示轮廓线 */
    114     font-family: Microsoft YaHei; /* 设置字体 */
    115     color: white; /* 字体颜色 */
    116     font-size: 17px; /* 字体大小 */
    117 }
    118 
    119 button:hover { /* 鼠标移入按钮范围时改变颜色 */
    120     background: #5599FF;
    121 }
    122 </style>
    123 <%
    124     String message = (String) session.getAttribute("message");
    125     if (message != null) {
    126 %>
    127 <script type="text/javascript">
    128     alert("<%=message%>");
    129     </script>
    130 <%
    131     session.removeAttribute("message");
    132     }
    133 %>
    134 <script type="text/javascript">
    135 function UpdateYard(id){
    136     var word=prompt("请输入修改后的结果:");
    137     word=encodeURIComponent(word);
    138     var sentence=confirm("是否确认修改!");
    139     if(sentence==true)
    140     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=yard";
    141 }
    142 function UpdateName(id){
    143     var word=prompt("请输入修改后的结果:");
    144     var sentence=confirm("是否确认修改!");
    145     word=encodeURIComponent(word);
    146     if(sentence==true)
    147     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=name";
    148 }
    149 function UpdateSex(id){
    150     var word=prompt("请输入修改后的结果:");
    151     var sentence=confirm("是否确认修改!");
    152     word=encodeURIComponent(word);
    153     if(sentence==true)
    154     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=sex";
    155 }
    156 function UpdateClas(id){
    157     var word=prompt("请输入修改后的结果:");
    158     var sentence=confirm("是否确认修改!");
    159     word=encodeURIComponent(word);
    160     if(sentence==true)
    161     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=clas";
    162 }
    163 
    164 </script>
    165 </head>
    166 <body onload="Onload()">
    167     <div id="d1">学生信息管理系统</div>
    168     <div id="left">
    169 <ul>
    170     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    171     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    172     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    173     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    174     <li><a href="AddUser.jsp">用户录入</a></li>
    175     <li><a href="ShowStudent">学生信息</a></li>
    176     <li><a href="ShowTeacher">教师信息</a></li>
    177     <li><a href="ShowUser">用户信息</a></li>
    178     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    179     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    180     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    181     <li><a href="Update.jsp">修改信息</a></li>
    182     <li><a href="ShowClass">选课</a></li>
    183     <li><a href="HaveSelected">已选课</a>
    184     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    185     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    186     <li><a href="AddClass.jsp">添加课程</a></li>
    187     <li><a href="ShowTeaClas">自己的课程</a></li>
    188     <%} %>    
    189     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    190 </ul>
    191     </div>
    192     <div id="right">
    193         <table>
    194             <c:forEach items="${list}" var="list">
    195                 <tr>
    196                     <td>工号:${list.id}</td>
    197                 </tr>
    198                 <tr>
    199                     <td>姓名:${list.name}</td>
    200                 </tr>
    201                 <tr>
    202                     <td>性别:${list.sex}</td>
    203                 </tr>
    204                 <tr>
    205                     <td>学院:${list.yard}</td>
    206                 </tr><tr>
    207                     <td>职称:${list.call}</td>
    208                 </tr>
    209             </c:forEach>
    210         </table>
    211     </div>
    212 </body>
    213 </html>
    TeaShowMySession.jsp

    删除:

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.SQLException;
     6 import java.sql.Statement;
     7 
     8 import javax.servlet.ServletException;
     9 import javax.servlet.annotation.WebServlet;
    10 import javax.servlet.http.HttpServlet;
    11 import javax.servlet.http.HttpServletRequest;
    12 import javax.servlet.http.HttpServletResponse;
    13 @WebServlet("/DeleteTeacher")
    14 public class DeleteTeacher extends HttpServlet {
    15     private static final long serialVersionUID = 1L;
    16     public DeleteTeacher() {
    17         super();
    18     }
    19     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    20         String id=request.getParameter("id");
    21         Link l=new Link();
    22         try {
    23             Connection con=l.lin("Class_Select");
    24             Statement stmt=con.createStatement();
    25             String s="delete User_Teacher where id='"+id+"'";
    26             stmt.executeUpdate(s);
    27         } catch (SQLException e) {
    28             e.printStackTrace();
    29         }
    30         request.getSession().setAttribute("message", "删除成功!");
    31         request.getRequestDispatcher("ShowTeacher").forward(request, response);
    32     }
    33 
    34     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    35         doGet(request, response);
    36     }
    37 
    38 }
    DeleteTeacher

    查询:

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/SearchTeaByName")
    16 public class SearchTeaByName extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public SearchTeaByName() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         String name=request.getParameter("name");
    23         ArrayList<TeacherBean> list=new ArrayList<>();
    24         int flag=0;
    25         System.out.println(name);
    26         if(name!=""&&name!=null) {
    27             Link l=new Link();
    28             try {
    29                 Connection con=l.lin("Class_Select");
    30                 Statement stmt=con.createStatement();
    31                 ResultSet rsst=stmt.executeQuery("select * from User_Teacher where name='"+name+"'");
    32                 while(rsst.next()) {
    33                     TeacherBean st=new TeacherBean();
    34                     st.setId(rsst.getString(1));
    35                     st.setName(rsst.getString(2));
    36                     st.setSex(rsst.getString(3));
    37                     st.setYard(rsst.getString(4));
    38                     st.setCall(rsst.getString(5));
    39                     list.add(st);
    40                     flag=1;
    41                 }
    42             } catch (SQLException e) {
    43                 // TODO Auto-generated catch block
    44                 e.printStackTrace();
    45             }
    46 
    47     }
    48         if(flag==0) {
    49             System.out.println(1111111);
    50             request.getSession().setAttribute("message", "查无此人!");
    51             request.getRequestDispatcher("ShowTeacher").forward(request,response);
    52         }else {
    53             request.getSession().setAttribute("list", list);
    54             System.out.println(1);
    55             request.getRequestDispatcher("ShowTeacher.jsp").forward(request,response);
    56         }
    57     }
    58     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    59         doGet(request, response);
    60     }
    61 
    62 }
    SearchTeaByName
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/SearchTeaByClas")
    16 public class SearchTeaByClas extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public SearchTeaByClas() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         String clas=request.getParameter("clas");
    23         ArrayList<TeacherBean> list=new ArrayList<>();
    24         int flag=0;
    25         if(clas!=""&&clas!=null) {
    26             Link l=new Link();
    27             try {
    28                 Connection con=l.lin("Class_Select");
    29                 Statement stmt=con.createStatement();
    30                 ResultSet rsst=stmt.executeQuery("select * from User_Teacher where yard='"+clas+"'");
    31                 while(rsst.next()) {
    32                     TeacherBean st=new TeacherBean();
    33                     st.setId(rsst.getString(1));
    34                     st.setName(rsst.getString(2));
    35                     st.setSex(rsst.getString(3));
    36                     st.setYard(rsst.getString(4));
    37                     st.setCall(rsst.getString(5));
    38                     list.add(st);
    39                     flag=1;
    40                 }
    41             } catch (SQLException e) {
    42                 // TODO Auto-generated catch block
    43                 e.printStackTrace();
    44             }
    45 
    46     }
    47         if(flag==0) {
    48             System.out.println(1111111);
    49             request.getSession().setAttribute("message", "查无此系!");
    50             request.getRequestDispatcher("ShowTeacher").forward(request,response);
    51         }else {
    52             request.getSession().setAttribute("list", list);
    53             System.out.println(1);
    54             request.getRequestDispatcher("ShowTeacher.jsp").forward(request,response);
    55         }
    56     }
    57     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    58         doGet(request, response);
    59     }
    60 
    61 }
    SearchTeaByClas

    用户信息界面:

    显示所有可登录此系统的账户,可对用户信息进行删除,但不可对root类型用户操作

     

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/ShowUser")
    16 public class ShowUser extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public ShowUser() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         ArrayList<UserBean> arr=new ArrayList<UserBean>();
    23         Link l=new Link();
    24         try {
    25             Connection con=l.lin("Class_Select");
    26             Statement stmt=con.createStatement();
    27             String s="select * from userr";
    28             ResultSet rsst=stmt.executeQuery(s);
    29             while(rsst.next()) {
    30                 UserBean ub=new UserBean();
    31                 ub.setUsername(rsst.getString(1));
    32                 ub.setPassword(rsst.getString(2));
    33                 ub.setType(rsst.getString(3));
    34                 arr.add(ub);
    35             }
    36         } catch (SQLException e) {
    37             e.printStackTrace();
    38         }
    39         request.setAttribute("list", arr);
    40         request.getRequestDispatcher("ShowUser.jsp").forward(request, response);
    41     }
    42     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    43         doGet(request, response);
    44     }
    45 
    46 }
    ShowUser.java
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 
      5 <!DOCTYPE html>
      6 <html>
      7 <head>
      8 <meta charset="UTF-8">
      9 <title>Document</title>
     10 <style type="text/css">
     11 #d1 {
     12     text-align: center;
     13     padding-top: 40px;
     14     font-family: "微软雅黑";
     15     font-size: 40px;
     16     background-color: #DDDDDD;
     17     height: 100px;
     18 }
     19 
     20 div ul {
     21     vertical-align: top;
     22     list-style-type: none;
     23     margin: 0px;
     24     vertical-align: left;
     25     width: 200px;
     26     padding: 0px;
     27     border-top: 20px solid #F8A0E7;
     28     border-bottom: 20px solid #F8A0E7;
     29 }
     30 
     31 .headd {
     32     font-family: "微软雅黑";
     33     lighting-color: red;
     34     font-size: 20px;
     35 }
     36 
     37 div li a {
     38     height: 80px;
     39     display: block;
     40     padding: 0px 0px 0px 0em;
     41     text-decoration: none;
     42     border-left: 20px solid pink;
     43 }
     44 
     45 div li a:link, div li a:visited {
     46     background-color: #F0F0F0;
     47     color: #461737;
     48 }
     49 
     50 div li a:hover {
     51     background-color: green;
     52     color: gray;
     53 }
     54 
     55 div li a:active {
     56     background-color: pink;
     57 }
     58 
     59 #left {
     60     float: left;
     61 }
     62 
     63 #right {
     64     height: 400px;
     65     width: 1100px;
     66     float: left;
     67 }
     68 
     69 #inp {
     70     float: left;
     71     height: 400px;
     72     width: 1202px;
     73 }
     74 
     75 .btn {
     76     float: left;
     77 }
     78 
     79 table {
     80     width: 1100px;
     81     height: 500px;
     82     border-collapse: collapse;
     83     margin: 0 auto;
     84     text-align: center;
     85 }
     86 
     87 table td, table th {
     88     border: 1px solid #cad9ea;
     89     color: #666;
     90     height: 30px;
     91 }
     92 
     93 table thead th {
     94     background-color: #CCE8EB;
     95     width: 100px;
     96 }
     97 
     98 table tr:nth-child(odd) {
     99     background: #fff;
    100 }
    101 
    102 table tr:nth-child(even) {
    103     background: #F5FAFA;
    104 }
    105 
    106 button { /* 按钮美化 */
    107     width: 270px; /* 宽度 */
    108     height: 40px; /* 高度 */
    109     border-width: 0px; /* 边框宽度 */
    110     border-radius: 3px; /* 边框半径 */
    111     background: #1E90FF; /* 背景颜色 */
    112     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    113     outline: none; /* 不显示轮廓线 */
    114     font-family: Microsoft YaHei; /* 设置字体 */
    115     color: white; /* 字体颜色 */
    116     font-size: 17px; /* 字体大小 */
    117 }
    118 
    119 button:hover { /* 鼠标移入按钮范围时改变颜色 */
    120     background: #5599FF;
    121 }
    122 </style>
    123 <%
    124     String message = (String) session.getAttribute("message");
    125     if (message != null) {
    126 %>
    127 <script type="text/javascript">
    128     alert("<%=message%>");
    129     </script>
    130 <%
    131     session.removeAttribute("message");
    132     }
    133 %>
    134 <script type="text/javascript">
    135 function Borrow(id){
    136     window.location.href="DeleteUser?id="+id;
    137 }
    138 
    139 </script>
    140 </head>
    141 <body onload="Onload()">
    142     <div id="d1">学生信息管理系统</div>
    143     <div id="left">
    144 <ul>
    145     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    146     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    147     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    148     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    149     <li><a href="AddUser.jsp">用户录入</a></li>
    150     <li><a href="ShowStudent">学生信息</a></li>
    151     <li><a href="ShowTeacher">教师信息</a></li>
    152     <li><a href="ShowUser">用户信息</a></li>
    153     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    154     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    155     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    156     <li><a href="Update.jsp">修改信息</a></li>
    157     <li><a href="ShowClass">选课</a></li>
    158     <li><a href="HaveSelected">已选课</a>
    159     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    160     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    161     <li><a href="AddClass.jsp">添加课程</a></li>
    162     <li><a href="ShowTeaClas">自己的课程</a></li>
    163     <%} %>    
    164     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    165 </ul>
    166     </div>
    167     <div id="right">
    168         <table>
    169             <c:forEach items="${list}" var="list">
    170                 <tr>
    171                     <td>账号:${list.username}</td>
    172                     <td>密码: ${list.password}</td>
    173                     <td>账号类型:${list.type}</td>
    174                     <c:if test="${list.username!='root'}">
    175                     <td><button onclick="Borrow(${list.username})">删除</button></td></c:if>
    176                     </tr>
    177             </c:forEach>
    178         </table>
    179     </div>
    180 </body>
    181 </html>
    ShowUser.jsp
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.SQLException;
     6 import java.sql.Statement;
     7 
     8 import javax.servlet.ServletException;
     9 import javax.servlet.annotation.WebServlet;
    10 import javax.servlet.http.HttpServlet;
    11 import javax.servlet.http.HttpServletRequest;
    12 import javax.servlet.http.HttpServletResponse;
    13 @WebServlet("/DeleteUser")
    14 public class DeleteUser extends HttpServlet {
    15     private static final long serialVersionUID = 1L;
    16     public DeleteUser() {
    17         super();
    18     }
    19     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    20         String username=request.getParameter("id");
    21         Link l=new Link();
    22         try {
    23             Connection con=l.lin("Class_Select");
    24             Statement stmt=con.createStatement();
    25             String s="delete userr where username='"+username+"'";
    26             stmt.executeUpdate(s);
    27         } catch (SQLException e) {
    28             e.printStackTrace();
    29         }
    30         request.getSession().setAttribute("message", "删除成功!");
    31         request.getRequestDispatcher("ShowUser").forward(request, response);
    32     }
    33 
    34     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    35         doGet(request, response);
    36     }
    37 
    38 }
    DeleteUser.java

    统计学生信息界面:

    对学生信息进行筛选,不需要的选框不填即可,在AnalyseServal中对各种搜索情况进行判断

     例如查询性别为女的学生:

     显示查询结果与结果数量:

     

     

     查询界面:

      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 
      5 <!DOCTYPE html>
      6 <html>
      7 <head>
      8 <meta charset="UTF-8">
      9 <title>Document</title>
     10 <style type="text/css">
     11 #d1 {
     12     text-align: center;
     13     padding-top: 40px;
     14     font-family: "微软雅黑";
     15     font-size: 40px;
     16     background-color: #DDDDDD;
     17     height: 100px;
     18 }
     19 
     20 div ul {
     21     vertical-align: top;
     22     list-style-type: none;
     23     margin: 0px;
     24     vertical-align: left;
     25     width: 200px;
     26     padding: 0px;
     27     border-top: 20px solid #F8A0E7;
     28     border-bottom: 20px solid #F8A0E7;
     29 }
     30 
     31 .headd {
     32     font-family: "微软雅黑";
     33     lighting-color: red;
     34     font-size: 20px;
     35 }
     36 
     37 div li a {
     38     height: 80px;
     39     display: block;
     40     padding: 0px 0px 0px 0em;
     41     text-decoration: none;
     42     border-left: 20px solid pink;
     43 }
     44 
     45 div li a:link, div li a:visited {
     46     background-color: #F0F0F0;
     47     color: #461737;
     48 }
     49 
     50 div li a:hover {
     51     background-color: green;
     52     color: gray;
     53 }
     54 
     55 div li a:active {
     56     background-color: pink;
     57 }
     58 
     59 #left {
     60     float: left;
     61 }
     62 
     63 #right {
     64     height: 400px;
     65     width: 1100px;
     66     float: left;
     67 }
     68 
     69 #inp {
     70     float: left;
     71     height: 400px;
     72     width: 1202px;
     73 }
     74 
     75 .btn {
     76     float: left;
     77 }
     78 
     79 table {
     80     width: 1300px;
     81     height: 500px;
     82     border-collapse: collapse;
     83     margin: 0 auto;
     84     text-align: center;
     85 }
     86 
     87 table td, table th {
     88     border: 1px solid #cad9ea;
     89     color: #666;
     90     height: 30px;
     91 }
     92 
     93 table thead th {
     94     background-color: #CCE8EB;
     95     width: 100px;
     96 }
     97 
     98 table tr:nth-child(odd) {
     99     background: #fff;
    100 }
    101 
    102 table tr:nth-child(even) {
    103     background: #F5FAFA;
    104 }
    105 
    106 button { /* 按钮美化 */
    107     width: 270px; /* 宽度 */
    108     height: 40px; /* 高度 */
    109     border-width: 0px; /* 边框宽度 */
    110     border-radius: 3px; /* 边框半径 */
    111     background: #1E90FF; /* 背景颜色 */
    112     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    113     outline: none; /* 不显示轮廓线 */
    114     font-family: Microsoft YaHei; /* 设置字体 */
    115     color: white; /* 字体颜色 */
    116     font-size: 17px; /* 字体大小 */
    117 }
    118 
    119 button:hover { /* 鼠标移入按钮范围时改变颜色 */
    120     background: #5599FF;
    121 }
    122 </style>
    123 <%
    124     String message = (String) session.getAttribute("message");
    125     if (message != null) {
    126 %>
    127 <script type="text/javascript">
    128     alert("<%=message%>");
    129     </script>
    130 <%
    131     session.removeAttribute("message");
    132     }
    133 %>
    134 <script type="text/javascript">
    135 function Borrow(id){
    136     window.location.href="DeleteStudent?id="+id;
    137 }
    138 </script>
    139 </head>
    140 <body onload="Onload()">
    141     <div id="d1">学生信息管理系统</div>
    142     <div id="left">
    143 <ul>
    144     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    145     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    146     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    147     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    148     <li><a href="AddUser.jsp">用户录入</a></li>
    149     <li><a href="ShowStudent">学生信息</a></li>
    150     <li><a href="ShowTeacher">教师信息</a></li>
    151     <li><a href="ShowUser">用户信息</a></li>
    152     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    153     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    154     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    155     <li><a href="Update.jsp">修改信息</a></li>
    156     <li><a href="ShowClass">选课</a></li>
    157     <li><a href="HaveSelected">已选课</a>
    158     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    159     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    160     <li><a href="AddClass.jsp">添加课程</a></li>
    161     <li><a href="ShowTeaClas">自己的课程</a></li>
    162     <%} %>    
    163     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    164 </ul>
    165     </div>
    166     <div id="right">
    167     <form action="AnalyseServal">
    168         <table>
    169                 <tr><td colspan="2">综合筛选</td></tr>
    170                 <tr>
    171                 <td>学院:</td>
    172                 <td><input type="text" name="yard"></td>
    173                 </tr><tr>
    174                 <td>班级:</td>
    175                 <td><input type="text" name="clas"></td>
    176                 </tr>
    177                 <tr>
    178                 <td>性别:</td>
    179                 <td><input type="radio" name="sex" id="sex" value="男">&nbsp &nbsp<input type="radio" name="sex" id="sex" value="女"></td>
    180                 </tr>
    181                 <tr>
    182                 <td>姓名:</td>
    183                 <td colspan="0.5"><input type="text" name="name"></td><td conspan="0.5"><input type="radio" name="type" id="type" value="精确">精确&nbsp &nbsp<input type="radio" name="type" id="type" value="模糊">模糊</td>
    184                 </tr>
    185                 <tr><td colspan="3"><button type="submit">查询</button></td></tr>
    186         </table>
    187     </form>
    188     </div>
    189 </body>
    190 </html>
    AnalyseSum.jsp

    查询:

      1 package p1;
      2 
      3 import java.io.IOException;
      4 import java.sql.Connection;
      5 import java.sql.ResultSet;
      6 import java.sql.SQLException;
      7 import java.sql.Statement;
      8 import java.util.ArrayList;
      9 
     10 import javax.servlet.ServletException;
     11 import javax.servlet.annotation.WebServlet;
     12 import javax.servlet.http.HttpServlet;
     13 import javax.servlet.http.HttpServletRequest;
     14 import javax.servlet.http.HttpServletResponse;
     15 
     16 @WebServlet("/AnalyseServal")
     17 public class AnalyseServal extends HttpServlet {
     18     private static final long serialVersionUID = 1L;
     19 
     20     public AnalyseServal() {
     21         super();
     22     }
     23 
     24     protected void doGet(HttpServletRequest request, HttpServletResponse response)
     25             throws ServletException, IOException {
     26         String name = request.getParameter("name");
     27         String yard = request.getParameter("yard");
     28         String clas = request.getParameter("clas");
     29         String[] sexx = request.getParameterValues("sex");
     30         String[] typee = request.getParameterValues("type");
     31         String sex = null;
     32         String type = null;
     33         int number = 0;
     34         ArrayList<StudentBean> list = new ArrayList<StudentBean>();
     35         if (sexx != null) {
     36             for (int i = 0; i < sexx.length; i++) {
     37 
     38                 if (sexx[i] != null)
     39                     sex = sexx[i];
     40             }
     41         }
     42         if (typee != null) {
     43             for (int i = 0; i < typee.length; i++) {
     44 
     45                 if (typee[i] != null)
     46                     type = typee[i];
     47 
     48             }
     49         }
     50 
     51         String s = "";
     52         if (name == null && yard == null && clas == null && sex == null) {
     53             s = "select * from User_Student";
     54         } else {
     55             s = "select * from User_Student where";
     56             if (name != null && name != "") {
     57                 if (type != null) {
     58                     if (type.equals("精确"))
     59                         s += (" name='" + name + "'");
     60                     else
     61                         s += (" name like '%" + name + "%'");
     62                 } else
     63                     s += (" name like '%" + name + "%'");
     64 
     65                 if (yard != null && yard != "") {
     66                     s += (" and yard like'%" + yard + "%'");
     67                 }
     68                 if (clas != null && clas != "") {
     69                     s += (" and clas like'%" + clas + "%'");
     70                 }
     71                 if (sex != null && sex != "") {
     72                     s += (" and sex='" + sex + "'");
     73                 }
     74             } else {
     75                 if (yard != null && yard != "") {
     76                     s += (" yard like'%" + yard + "%'");
     77                     if (clas != null && clas != "") {
     78                         s += (" and clas like'%" + clas + "%'");
     79                     }
     80                     if (sex != null && sex != "") {
     81                         s += (" and sex='" + sex + "'");
     82                     }
     83                 } else {
     84                     if (clas != null && clas != "") {
     85                         s += (" clas like'%" + clas + "%'");
     86                         if (sex != null && sex != "") {
     87                             s += (" and sex='" + sex + "'");
     88                         }
     89                     } else {
     90                         if (sex != null && sex != "") {
     91                             s += (" sex='" + sex + "'");
     92                         }
     93                     }
     94                 }
     95             }
     96         }
     97         Link l = new Link();
     98         try {
     99             System.out.println(s);
    100             Connection con = l.lin("Class_Select");
    101             Statement stmt = con.createStatement();
    102             ResultSet rsst = stmt.executeQuery(s);
    103             while (rsst.next()) {
    104                 StudentBean sb = new StudentBean();
    105                 sb.setId(rsst.getString(1));
    106                 sb.setName(rsst.getString(2));
    107                 sb.setSex(rsst.getString(3));
    108                 sb.setYard(rsst.getString(4));
    109                 sb.setClas(rsst.getString(5));
    110                 list.add(sb);
    111                 number++;
    112             }
    113         } catch (SQLException e) {
    114             // TODO Auto-generated catch block
    115             e.printStackTrace();
    116         }
    117         request.getSession().setAttribute("list", list);
    118         request.getSession().setAttribute("number", number);
    119         request.getRequestDispatcher("AnalyseResult.jsp").forward(request, response);
    120     }
    121 
    122     protected void doPost(HttpServletRequest request, HttpServletResponse response)
    123             throws ServletException, IOException {
    124         // TODO Auto-generated method stub
    125         doGet(request, response);
    126     }
    127 
    128 }
    AnalyseServal.java

    查询结果:

      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 
      5 <!DOCTYPE html>
      6 <html>
      7 <head>
      8 <meta charset="UTF-8">
      9 <title>Document</title>
     10 <style type="text/css">
     11 #d1 {
     12     text-align: center;
     13     padding-top: 40px;
     14     font-family: "微软雅黑";
     15     font-size: 40px;
     16     background-color: #DDDDDD;
     17     height: 100px;
     18 }
     19 
     20 div ul {
     21     vertical-align: top;
     22     list-style-type: none;
     23     margin: 0px;
     24     vertical-align: left;
     25     width: 200px;
     26     padding: 0px;
     27     border-top: 20px solid #F8A0E7;
     28     border-bottom: 20px solid #F8A0E7;
     29 }
     30 
     31 .headd {
     32     font-family: "微软雅黑";
     33     lighting-color: red;
     34     font-size: 20px;
     35 }
     36 
     37 div li a {
     38     height: 80px;
     39     display: block;
     40     padding: 0px 0px 0px 0em;
     41     text-decoration: none;
     42     border-left: 20px solid pink;
     43 }
     44 
     45 div li a:link, div li a:visited {
     46     background-color: #F0F0F0;
     47     color: #461737;
     48 }
     49 
     50 div li a:hover {
     51     background-color: green;
     52     color: gray;
     53 }
     54 
     55 div li a:active {
     56     background-color: pink;
     57 }
     58 
     59 #left {
     60     float: left;
     61 }
     62 
     63 #right {
     64     height: 400px;
     65     width: 1100px;
     66     float: left;
     67 }
     68 
     69 #inp {
     70     float: left;
     71     height: 400px;
     72     width: 1202px;
     73 }
     74 
     75 .btn {
     76     float: left;
     77 }
     78 
     79 table {
     80     width: 1300px;
     81     height: 500px;
     82     border-collapse: collapse;
     83     margin: 0 auto;
     84     text-align: center;
     85 }
     86 
     87 table td, table th {
     88     border: 1px solid #cad9ea;
     89     color: #666;
     90     height: 30px;
     91 }
     92 
     93 table thead th {
     94     background-color: #CCE8EB;
     95     width: 100px;
     96 }
     97 
     98 table tr:nth-child(odd) {
     99     background: #fff;
    100 }
    101 
    102 table tr:nth-child(even) {
    103     background: #F5FAFA;
    104 }
    105 
    106 button { /* 按钮美化 */
    107     width: 270px; /* 宽度 */
    108     height: 40px; /* 高度 */
    109     border-width: 0px; /* 边框宽度 */
    110     border-radius: 3px; /* 边框半径 */
    111     background: #1E90FF; /* 背景颜色 */
    112     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    113     outline: none; /* 不显示轮廓线 */
    114     font-family: Microsoft YaHei; /* 设置字体 */
    115     color: white; /* 字体颜色 */
    116     font-size: 17px; /* 字体大小 */
    117 }
    118 
    119 button:hover { /* 鼠标移入按钮范围时改变颜色 */
    120     background: #5599FF;
    121 }
    122 </style>
    123 <%
    124     String message = (String) session.getAttribute("message");
    125     if (message != null) {
    126 %>
    127 <script type="text/javascript">
    128     alert("<%=message%>");
    129     </script>
    130 <%
    131     session.removeAttribute("message");
    132     }
    133 %>
    134 <script type="text/javascript">
    135 function Borrow(id){
    136     window.location.href="DeleteStudent?id="+id;
    137 }
    138 </script>
    139 </head>
    140 <body onload="Onload()">
    141     <div id="d1">学生信息管理系统</div>
    142     <div id="left">
    143 <ul>
    144     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    145     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    146     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    147     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    148     <li><a href="AddUser.jsp">用户录入</a></li>
    149     <li><a href="ShowStudent">学生信息</a></li>
    150     <li><a href="ShowTeacher">教师信息</a></li>
    151     <li><a href="ShowUser">用户信息</a></li>
    152     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    153     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    154     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    155     <li><a href="Update.jsp">修改信息</a></li>
    156     <li><a href="ShowClass">选课</a></li>
    157     <li><a href="HaveSelected">已选课</a>
    158     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    159     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    160     <li><a href="AddClass.jsp">添加课程</a></li>
    161     <li><a href="ShowTeaClas">自己的课程</a></li>
    162     <%} %>    
    163     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    164 </ul>
    165     </div>
    166     <div id="right">
    167         <table>
    168             <tr><td colspan="5">查询结果:</td><td colspan="3">${number}</td></tr>
    169     <c:forEach items="${list}" var="list">
    170                 <tr>
    171                     <td>学院:${list.yard}</td>
    172                     <td>班级:${list.clas}</td>
    173                     <td>姓名:${list.name}</td>
    174                     <td>性别:${list.sex}</td>
    175                     <td>学号:${list.id}</td>
    176                     <td colspan="2"><button onclick="Borrow(${list.id})">删除</button></td>
    177                 </tr>
    178             </c:forEach>
    179         </table>
    180     </div>
    181 </body>
    182 </html>
    AnalyseResult.jsp

    修改密码:

    输入原密码,新密码并确认密码,判断新密码与原密码相同时不能修改,新密码与确认密码不相同时也不能修改

     

     

     在servlet中判断原密码错误并返回修改密码界面

     成功修改:

    教师功能页:

    我的信息:从教师表中读取教师本人信息存储到Bean中传输到jsp,不提供修改

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/ShowTeaSession")
    16 public class ShowTeaSession extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public ShowTeaSession() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         Link l=new Link();
    23         String id=request.getParameter("id");
    24         ArrayList<TeacherBean> list=new ArrayList<TeacherBean>();
    25         try {
    26             Connection con=l.lin("Class_Select");
    27             Statement stmt=con.createStatement();
    28             String s="select * from User_Teacher where id="+id;
    29             ResultSet rsst=stmt.executeQuery(s);
    30             while(rsst.next()) {
    31                 TeacherBean bk=new TeacherBean();
    32                 bk.setId(rsst.getString("id"));
    33                 bk.setName(rsst.getString("name"));
    34                 bk.setSex(rsst.getString("sex"));
    35                 bk.setYard(rsst.getString("yard"));
    36                 bk.setCall(rsst.getString("call"));
    37                 list.add(bk);
    38             }
    39             stmt.close();
    40             rsst.close();
    41             con.close();
    42         } catch (SQLException e) {
    43             // TODO Auto-generated catch block
    44             e.printStackTrace();
    45         }
    46         request.setAttribute("list", list);
    47         request.getRequestDispatcher("TeaShowMySession.jsp").forward(request, response);
    48     }
    49     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    50         // TODO Auto-generated method stub
    51         doGet(request, response);
    52     }
    53 
    54 }
    ShowTeaSession.java
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 
      5 <!DOCTYPE html>
      6 <html>
      7 <head>
      8 <meta charset="UTF-8">
      9 <title>Document</title>
     10 <style type="text/css">
     11 #d1 {
     12     text-align: center;
     13     padding-top: 40px;
     14     font-family: "微软雅黑";
     15     font-size: 40px;
     16     background-color: #DDDDDD;
     17     height: 100px;
     18 }
     19 
     20 div ul {
     21     vertical-align: top;
     22     list-style-type: none;
     23     margin: 0px;
     24     vertical-align: left;
     25     width: 200px;
     26     padding: 0px;
     27     border-top: 20px solid #F8A0E7;
     28     border-bottom: 20px solid #F8A0E7;
     29 }
     30 
     31 .headd {
     32     font-family: "微软雅黑";
     33     lighting-color: red;
     34     font-size: 20px;
     35 }
     36 
     37 div li a {
     38     height: 80px;
     39     display: block;
     40     padding: 0px 0px 0px 0em;
     41     text-decoration: none;
     42     border-left: 20px solid pink;
     43 }
     44 
     45 div li a:link, div li a:visited {
     46     background-color: #F0F0F0;
     47     color: #461737;
     48 }
     49 
     50 div li a:hover {
     51     background-color: green;
     52     color: gray;
     53 }
     54 
     55 div li a:active {
     56     background-color: pink;
     57 }
     58 
     59 #left {
     60     float: left;
     61 }
     62 
     63 #right {
     64     height: 400px;
     65     width: 1100px;
     66     float: left;
     67 }
     68 
     69 #inp {
     70     float: left;
     71     height: 400px;
     72     width: 1202px;
     73 }
     74 
     75 .btn {
     76     float: left;
     77 }
     78 
     79 table {
     80     width: 1300px;
     81     height: 500px;
     82     border-collapse: collapse;
     83     margin: 0 auto;
     84     text-align: center;
     85 }
     86 
     87 table td, table th {
     88     border: 1px solid #cad9ea;
     89     color: #666;
     90     height: 30px;
     91 }
     92 
     93 table thead th {
     94     background-color: #CCE8EB;
     95     width: 100px;
     96 }
     97 
     98 table tr:nth-child(odd) {
     99     background: #fff;
    100 }
    101 
    102 table tr:nth-child(even) {
    103     background: #F5FAFA;
    104 }
    105 
    106 button { /* 按钮美化 */
    107     width: 270px; /* 宽度 */
    108     height: 40px; /* 高度 */
    109     border-width: 0px; /* 边框宽度 */
    110     border-radius: 3px; /* 边框半径 */
    111     background: #1E90FF; /* 背景颜色 */
    112     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    113     outline: none; /* 不显示轮廓线 */
    114     font-family: Microsoft YaHei; /* 设置字体 */
    115     color: white; /* 字体颜色 */
    116     font-size: 17px; /* 字体大小 */
    117 }
    118 
    119 button:hover { /* 鼠标移入按钮范围时改变颜色 */
    120     background: #5599FF;
    121 }
    122 </style>
    123 <%
    124     String message = (String) session.getAttribute("message");
    125     if (message != null) {
    126 %>
    127 <script type="text/javascript">
    128     alert("<%=message%>");
    129     </script>
    130 <%
    131     session.removeAttribute("message");
    132     }
    133 %>
    134 <script type="text/javascript">
    135 function UpdateYard(id){
    136     var word=prompt("请输入修改后的结果:");
    137     word=encodeURIComponent(word);
    138     var sentence=confirm("是否确认修改!");
    139     if(sentence==true)
    140     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=yard";
    141 }
    142 function UpdateName(id){
    143     var word=prompt("请输入修改后的结果:");
    144     var sentence=confirm("是否确认修改!");
    145     word=encodeURIComponent(word);
    146     if(sentence==true)
    147     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=name";
    148 }
    149 function UpdateSex(id){
    150     var word=prompt("请输入修改后的结果:");
    151     var sentence=confirm("是否确认修改!");
    152     word=encodeURIComponent(word);
    153     if(sentence==true)
    154     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=sex";
    155 }
    156 function UpdateClas(id){
    157     var word=prompt("请输入修改后的结果:");
    158     var sentence=confirm("是否确认修改!");
    159     word=encodeURIComponent(word);
    160     if(sentence==true)
    161     window.location.href="UpdateStudent?id="+id+"&word="+word+"&type=clas";
    162 }
    163 
    164 </script>
    165 </head>
    166 <body onload="Onload()">
    167     <div id="d1">学生信息管理系统</div>
    168     <div id="left">
    169 <ul>
    170     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    171     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    172     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    173     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    174     <li><a href="AddUser.jsp">用户录入</a></li>
    175     <li><a href="ShowStudent">学生信息</a></li>
    176     <li><a href="ShowTeacher">教师信息</a></li>
    177     <li><a href="ShowUser">用户信息</a></li>
    178     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    179     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    180     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    181     <li><a href="Update.jsp">修改信息</a></li>
    182     <li><a href="ShowClass">选课</a></li>
    183     <li><a href="HaveSelected">已选课</a>
    184     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    185     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    186     <li><a href="AddClass.jsp">添加课程</a></li>
    187     <li><a href="ShowTeaClas">自己的课程</a></li>
    188     <%} %>    
    189     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    190 </ul>
    191     </div>
    192     <div id="right">
    193         <table>
    194             <c:forEach items="${list}" var="list">
    195                 <tr>
    196                     <td>工号:${list.id}</td>
    197                 </tr>
    198                 <tr>
    199                     <td>姓名:${list.name}</td>
    200                 </tr>
    201                 <tr>
    202                     <td>性别:${list.sex}</td>
    203                 </tr>
    204                 <tr>
    205                     <td>学院:${list.yard}</td>
    206                 </tr><tr>
    207                     <td>职称:${list.call}</td>
    208                 </tr>
    209             </c:forEach>
    210         </table>
    211     </div>
    212 </body>
    213 </html>
    TeaShowMySession

    添加课程:

    输入课程信息,添加课程到Clas表

     添加成功后跳回添加课程界面

      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <!DOCTYPE html>
      4 <html>
      5 <head>
      6 <meta charset="UTF-8">
      7 <title>Document</title>
      8 <style type="text/css">
      9         
     10         #d1{
     11             text-align: center;
     12             padding-top: 40px;
     13             font-family: "微软雅黑";
     14             font-size: 40px;
     15             background-color: #DDDDDD;
     16             height: 100px;
     17         }
     18         div ul{
     19             vertical-align: top;
     20             list-style-type: none;
     21             margin: 0px;
     22             vertical-align: left;
     23             width: 200px;
     24             padding: 0px;
     25             border-top: 20px solid #F8A0E7;
     26             border-bottom :20px solid #F8A0E7;
     27         }
     28         .headd{
     29             font-family: "微软雅黑";
     30             lighting-color: red;
     31             font-size: 20px;
     32         }
     33         div li a{
     34             height: 80px;
     35             display: block;
     36             padding: 0px 0px 0px 0em;
     37             text-decoration: none;
     38             border-left: 20px solid pink;
     39         }
     40         div li a:link,div li a:visited{
     41             background-color: #F0F0F0;
     42             color: #461737;
     43         }
     44         div li a:hover{
     45             background-color: green;
     46             color: gray;
     47         }
     48         div li a:active{
     49             background-color: pink;
     50         }
     51         #left{
     52         float:left;
     53         }
     54         #right{
     55         height:400px;
     56         width:1100px;
     57         float:left;
     58         }
     59         #inp{
     60         float:left;
     61         height:400px;
     62         width:1202px;
     63         }
     64         .btn{
     65         float:left;
     66         }
     67           table
     68         {
     69             width:1100px;
     70             height:500px;
     71             border-collapse: collapse;
     72             margin: 0 auto;
     73             text-align: center;
     74         }
     75         table td, table th
     76         {
     77             border: 1px solid #cad9ea;
     78             color: #666;
     79             height: 30px;
     80         }
     81         table thead th
     82         {
     83             background-color: #CCE8EB;
     84             width: 100px;
     85         }
     86         table tr:nth-child(odd)
     87         {
     88             background: #fff;
     89         }
     90         table tr:nth-child(even)
     91         {
     92             background: #F5FAFA;
     93         }
     94                 
     95     button { /* 按钮美化 */
     96     width: 270px; /* 宽度 */
     97     height: 40px; /* 高度 */
     98     border-width: 0px; /* 边框宽度 */
     99     border-radius: 3px; /* 边框半径 */
    100     background: #1E90FF; /* 背景颜色 */
    101     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    102     outline: none; /* 不显示轮廓线 */
    103     font-family: Microsoft YaHei; /* 设置字体 */
    104     color: white; /* 字体颜色 */
    105     font-size: 17px; /* 字体大小 */
    106 }
    107     button:hover { /* 鼠标移入按钮范围时改变颜色 */
    108     background: #5599FF;
    109     .headd{
    110             font-family: "微软雅黑";
    111             lighting-color: red;
    112             font-size: 20px;
    113         }
    114         div li a{
    115             height: 80px;
    116             display: block;
    117             padding: 0px 0px 0px 0em;
    118             text-decoration: none;
    119             border-left: 20px solid pink;
    120         }
    121         div li a:link,div li a:visited{
    122             background-color: #F0F0F0;
    123             color: #461737;
    124         }
    125         div li a:hover{
    126             background-color: green;
    127             color: gray;
    128         }
    129         div li a:active{
    130             background-color: pink;
    131         }
    132         #left{
    133         float:left;
    134         }
    135         #right{
    136         height:400px;
    137         width:1100px;
    138         float:left;
    139         border:1px solid green; 
    140         }
    141         #inp{
    142         float:left;
    143         height:400px;
    144         width:1202px;
    145         }
    146         .btn{
    147         float:left;
    148         }
    149 </style>
    150 <%String message=(String)session.getAttribute("message");
    151 if(message!=null){%>
    152     <script type="text/javascript">
    153     alert("<%=message%>");
    154     </script>
    155 <% session.removeAttribute("message");}
    156 
    157 %>
    158 
    159 
    160 <script type="text/javascript">
    161 function Out(){
    162     var title=document.getElementById("title").value;
    163     if(title=="") {
    164         alert("标题不能为空!!!");
    165         return false;
    166     }
    167     var text=encodeURIComponent(document.getElementById("inp").value);
    168     var s="SaveAritical?text="+text+"&type=Document&title="+encodeURIComponent(title);
    169     window.location.href=s;
    170 }
    171 function Save(){
    172     var title=document.getElementById("title").value;
    173     if(title=="") {
    174         alert("标题不能为空!!!");
    175         return false;
    176     }
    177     var text=encodeURIComponent(document.getElementById("inp").value);
    178     var s="OutAritical?text="+text+"&type=Document&title="+encodeURIComponent(title);
    179     window.location.href=s;
    180 }
    181 
    182 
    183 </script>
    184 </head>
    185 <body onload="Onload()">
    186     <div id="d1">图书管理系统</div>
    187     <div id="left">
    188 <ul>
    189     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    190     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    191     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    192     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    193     <li><a href="AddUser.jsp">用户录入</a></li>
    194     <li><a href="ShowStudent">学生信息</a></li>
    195     <li><a href="ShowTeacher">教师信息</a></li>
    196     <li><a href="ShowUser">用户信息</a></li>
    197     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    198     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    199     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    200     <li><a href="Update.jsp">修改信息</a></li>
    201     <li><a href="ShowClass">选课</a></li>
    202     <li><a href="HaveSelected">已选课</a>
    203     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    204     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    205     <li><a href="AddClass.jsp">添加课程</a></li>
    206     <li><a href="ShowTeaClas">自己的课程</a></li>
    207     <%} %>    
    208     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    209 </ul>
    210 </div>
    211 <div id="right">
    212 <form action="AddClass">
    213 <table>
    214 <tr>
    215 <td>课程名称:</td><td><input type="text" name="name" id="name"></td>
    216 </tr>
    217 <tr>
    218 <td>课程容量:</td><td><input type="text" name="number" id="number"></td></tr>
    219 <tr>
    220 <td colspan="2"><button type="submit" value="提 交">提交</button></td></tr>
    221 </table>
    222 </form>
    223 </div>
    224 </body>
    225 </html>
    AddClass.jsp
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 
     9 import javax.servlet.ServletException;
    10 import javax.servlet.annotation.WebServlet;
    11 import javax.servlet.http.HttpServlet;
    12 import javax.servlet.http.HttpServletRequest;
    13 import javax.servlet.http.HttpServletResponse;
    14 @WebServlet("/AddClass")
    15 public class AddClass extends HttpServlet {
    16     private static final long serialVersionUID = 1L;
    17     public AddClass() {
    18         super();
    19         // TODO Auto-generated constructor stub
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         String name=request.getParameter("name");
    23         String number=request.getParameter("number");
    24         String teacherid=(String)request.getSession().getAttribute("userid");
    25         Link l=new Link();
    26         try {
    27             Connection con=l.lin("Class_Select");
    28             Statement stmt=con.createStatement();
    29             String s="select * from Clas";
    30             ResultSet rsst=stmt.executeQuery(s);
    31             int num=2020001;
    32             while(rsst.next()) {
    33                 num=Integer.parseInt(rsst.getString("id"))+1;
    34             }
    35             rsst.close();
    36             s="insert into Clas values ('"+num+"','"+name+"','"+number+"','"+teacherid+"',null,0)";
    37             System.out.println(s);
    38             stmt.executeUpdate(s);
    39             stmt.close();
    40             con.close();
    41         } catch (SQLException e) {
    42             e.printStackTrace();
    43         }
    44         request.getSession().setAttribute("message", "添加成功!");
    45         request.getRequestDispatcher("AddClass.jsp").forward(request, response);
    46     }
    47     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    48         doGet(request, response);
    49     }
    50 
    51 }
    AddClass.java

     显示课程:

    从Clas表中读取自己的课程进行显示:

     点击删除课程可对课程进行删除。

    修改密码界面同管理员修改密码一致

    学生功能页:

    我的信息同教师信息页相同:

     选课界面:从Clas表中读取课程信息,存储到ClassBean中传到jsp

     点击选课,将学生id存储到asker中,选课人数加一,选课成功后跳回选课界面

     

    课程:

     1 package p1;
     2 
     3 public class ClasBean {
     4 private String id;
     5 private String name;
     6 private String number;
     7 private String nownumber;
     8 private String teacher;
     9 
    10 public String getId() {
    11     return id;
    12 }
    13 public void setId(String id) {
    14     this.id = id;
    15 }
    16 public String getTeacher() {
    17     return teacher;
    18 }
    19 public void setTeacher(String teacher) {
    20     this.teacher = teacher;
    21 }
    22 public String getName() {
    23     return name;
    24 }
    25 public void setName(String name) {
    26     this.name = name;
    27 }
    28 public String getNumber() {
    29     return number;
    30 }
    31 public String getNownumber() {
    32     return nownumber;
    33 }
    34 public void setNumber(String number) {
    35     this.number = number;
    36 }
    37 public void setNownumber(String nownumber) {
    38     this.nownumber = nownumber;
    39 }
    40 
    41 }
    ClasBean

    显示课程:

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/ShowClass")
    16 public class ShowClass extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public ShowClass() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         Link l=new Link();
    23         String id=(String)request.getSession().getAttribute("userid");
    24         ArrayList<ClasBean> list=new ArrayList<ClasBean>();
    25         try {
    26             Connection con=l.lin("Class_Select");
    27             Statement stmt=con.createStatement();
    28             String s="select * from Clas";
    29             ResultSet rsst=stmt.executeQuery(s);
    30             while(rsst.next()) {
    31                 ClasBean bk=new ClasBean();
    32                 bk.setId(rsst.getString("id"));
    33                 bk.setName(rsst.getString("name"));
    34                 bk.setNumber(rsst.getString("number"));
    35                 bk.setNownumber(rsst.getString("nownumber"));
    36                 bk.setTeacher(rsst.getString("teacher"));
    37                 System.out.println();
    38                 list.add(bk);
    39             }
    40             stmt.close();
    41             con.close();
    42         } catch (SQLException e) {
    43             // TODO Auto-generated catch block
    44             e.printStackTrace();
    45         }
    46         request.setAttribute("list", list);
    47         request.getRequestDispatcher("SelectClass.jsp").forward(request, response);
    48     }
    49     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    50         // TODO Auto-generated method stub
    51         doGet(request, response);
    52     }
    53 
    54 }
    ShowClass.java
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 <!DOCTYPE html>
      5 <html>
      6 <head>
      7 <meta charset="UTF-8">
      8 <title>Document</title>
      9 <style type="text/css">
     10     
     11         #d1{
     12             text-align: center;
     13             padding-top: 40px;
     14             font-family: "微软雅黑";
     15             font-size: 40px;
     16             background-color: #DDDDDD;
     17             height: 100px;
     18         }
     19         div ul{
     20             vertical-align: top;
     21             list-style-type: none;
     22             margin: 0px;
     23             vertical-align: left;
     24             width: 200px;
     25             padding: 0px;
     26             border-top: 20px solid #F8A0E7;
     27             border-bottom :20px solid #F8A0E7;
     28         }
     29         .headd{
     30             font-family: "微软雅黑";
     31             lighting-color: red;
     32             font-size: 20px;
     33         }
     34         div li a{
     35             height: 80px;
     36             display: block;
     37             padding: 0px 0px 0px 0em;
     38             text-decoration: none;
     39             border-left: 20px solid pink;
     40         }
     41         div li a:link,div li a:visited{
     42             background-color: #F0F0F0;
     43             color: #461737;
     44         }
     45         div li a:hover{
     46             background-color: green;
     47             color: gray;
     48         }
     49         div li a:active{
     50             background-color: pink;
     51         }
     52         #left{
     53         float:left;
     54         }
     55         #right{
     56         height:400px;
     57         width:1100px;
     58         float:left;
     59         }
     60         #inp{
     61         float:left;
     62         height:400px;
     63         width:1202px;
     64         }
     65         .btn{
     66         float:left;
     67         }
     68           table
     69         {
     70             width:1100px;
     71             height:500px;
     72             border-collapse: collapse;
     73             margin: 0 auto;
     74             text-align: center;
     75         }
     76         table td, table th
     77         {
     78             border: 1px solid #cad9ea;
     79             color: #666;
     80             height: 30px;
     81         }
     82         table thead th
     83         {
     84             background-color: #CCE8EB;
     85             width: 100px;
     86         }
     87         table tr:nth-child(odd)
     88         {
     89             background: #fff;
     90         }
     91         table tr:nth-child(even)
     92         {
     93             background: #F5FAFA;
     94         }
     95                 
     96     button { /* 按钮美化 */
     97     width: 270px; /* 宽度 */
     98     height: 40px; /* 高度 */
     99     border-width: 0px; /* 边框宽度 */
    100     border-radius: 3px; /* 边框半径 */
    101     background: #1E90FF; /* 背景颜色 */
    102     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    103     outline: none; /* 不显示轮廓线 */
    104     font-family: Microsoft YaHei; /* 设置字体 */
    105     color: white; /* 字体颜色 */
    106     font-size: 17px; /* 字体大小 */
    107 }
    108     button:hover { /* 鼠标移入按钮范围时改变颜色 */
    109     background: #5599FF;
    110 
    111 </style>
    112 <%
    113     String message = (String) session.getAttribute("message");
    114     if (message != null) {
    115 %>
    116 <script type="text/javascript">
    117     alert("<%=message%>");
    118 </script>
    119 <%
    120     session.removeAttribute("message");
    121     }
    122 %>
    123 <script>
    124 function ForDetail(id){
    125     window.location.href="ShowStudent?id="+id;
    126 }
    127 
    128 function ShowTeacher(id){
    129     window.location.href="ShowTeacher?id="+id;
    130 }
    131 function Borrow(id){
    132     window.location.href="SelectClass?id="+id;
    133 }
    134 
    135 </script>
    136 </head>
    137 <body onload="Onload()">
    138     <div id="d1">选课系统</div>
    139     <div id="left">
    140 <ul>
    141     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    142     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    143     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    144     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    145     <li><a href="AddUser.jsp">用户录入</a></li>
    146     <li><a href="ShowStudent">学生信息</a></li>
    147     <li><a href="ShowTeacher">教师信息</a></li>
    148     <li><a href="ShowUser">用户信息</a></li>
    149     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    150     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    151     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    152     <li><a href="ShowClass">选课</a></li>
    153     <li><a href="HaveSelected">已选课</a>
    154     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    155     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    156     <li><a href="AddClass.jsp">添加课程</a></li>
    157     <li><a href="ShowTeaClas">自己的课程</a></li>
    158     <%} %>    
    159     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    160 </ul>
    161 </div>
    162 <div id="right">
    163 <table>
    164 <c:forEach items="${list}" var="list">
    165 <tr>
    166 <td>课程编号:${list.id}</td>
    167 <td>课程名称:${list.name}</td>
    168 <td onclick="ShowTeacher(${list.teacher})">任课教师:${list.teacher}</td>
    169 <td>选课人数:${list.nownumber}</td>
    170 <td>课程容量: ${list.number}</td>
    171 <td><button onclick="Borrow(${list.id})">选课</button></td>
    172 </c:forEach>
    173 </table>
    174 </div>
    175 </body>
    176 </html>
    SelectClass.jsp

    选课:

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 
     9 import javax.servlet.ServletException;
    10 import javax.servlet.annotation.WebServlet;
    11 import javax.servlet.http.HttpServlet;
    12 import javax.servlet.http.HttpServletRequest;
    13 import javax.servlet.http.HttpServletResponse;
    14 @WebServlet("/SelectClass")
    15 public class SelectClass extends HttpServlet {
    16     private static final long serialVersionUID = 1L;
    17     public SelectClass() {
    18         super();
    19     }
    20     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    21         String id=request.getParameter("id");
    22         String userid=(String)request.getSession().getAttribute("userid");
    23         Link l=new Link();
    24         try {
    25             Connection con=l.lin("Class_Select");
    26             Statement stmt=con.createStatement();
    27             String s="update Clas set asker=asker+'_'+'"+userid+"' where id='"+id+"'";
    28             System.out.println(s);
    29             stmt.executeUpdate(s);
    30             Statement stmt2=con.createStatement();
    31             String s2="update Clas set nownumber=nownumber+1 where id='"+id+"'";
    32             stmt2.executeUpdate(s2);
    33             stmt2.close();
    34             stmt.close();
    35             con.close();
    36         } catch (SQLException e) {
    37             // TODO Auto-generated catch block
    38             e.printStackTrace();
    39         }
    40         request.getSession().setAttribute("message", "选课成功!");
    41         request.getRequestDispatcher("ShowClass").forward(request, response);
    42     }
    43     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    44         // TODO Auto-generated method stub
    45         doGet(request, response);
    46     }
    47 
    48 }
    SelectClass.java

    已选课:

    从Clas表中读取asker,分割字符串判断并显示已选课程

     已选课中可删除选中课程

     

     选课人数减一。

     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 import java.util.ArrayList;
     9 
    10 import javax.servlet.ServletException;
    11 import javax.servlet.annotation.WebServlet;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 @WebServlet("/HaveSelected")
    16 public class HaveSelected extends HttpServlet {
    17     private static final long serialVersionUID = 1L;
    18     public HaveSelected() {
    19         super();
    20     }
    21     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    22         String id=(String)request.getSession().getAttribute("userid");
    23         ArrayList<ClasBean> list=new ArrayList<>();
    24         Link l=new Link();
    25         try {
    26             Connection con=l.lin("Class_Select");
    27             Statement stmt=con.createStatement();
    28             String s="select * from Clas";
    29             ResultSet rsst=stmt.executeQuery(s);
    30             while(rsst.next()) {
    31                 String asker=rsst.getString("asker");
    32                 String[] ask=asker.split("_");
    33                 for(int i=0;i<ask.length;i++) {
    34                     if(ask[i].equals(id)) {
    35                     ClasBean cl=new ClasBean();
    36                     cl.setId(rsst.getString("id"));
    37                     cl.setName(rsst.getString("name"));
    38                     cl.setNumber(rsst.getString("number"));
    39                     cl.setNownumber(rsst.getString("nownumber"));
    40                     cl.setTeacher(rsst.getString("teacher"));
    41                     list.add(cl);
    42                     }
    43                 }
    44                 
    45             }
    46             rsst.close();
    47             stmt.close();
    48             con.close();
    49         } catch (SQLException e) {
    50             // TODO Auto-generated catch block
    51             e.printStackTrace();
    52         }
    53         request.setAttribute("list", list);
    54         request.getRequestDispatcher("HavenSelect.jsp").forward(request, response);
    55     }
    56     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    57         // TODO Auto-generated method stub
    58         doGet(request, response);
    59     }
    60 
    61 }
    HaveSelected.jvava
      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      4 <!DOCTYPE html>
      5 <html>
      6 <head>
      7 <meta charset="UTF-8">
      8 <title>Document</title>
      9 <style type="text/css">
     10 
     11         #d1{
     12             text-align: center;
     13             padding-top: 40px;
     14             font-family: "微软雅黑";
     15             font-size: 40px;
     16             background-color: #DDDDDD;
     17             height: 100px;
     18         }
     19         div ul{
     20             vertical-align: top;
     21             list-style-type: none;
     22             margin: 0px;
     23             vertical-align: left;
     24             width: 200px;
     25             padding: 0px;
     26             border-top: 20px solid #F8A0E7;
     27             border-bottom :20px solid #F8A0E7;
     28         }
     29         .headd{
     30             font-family: "微软雅黑";
     31             lighting-color: red;
     32             font-size: 20px;
     33         }
     34         div li a{
     35             height: 80px;
     36             display: block;
     37             padding: 0px 0px 0px 0em;
     38             text-decoration: none;
     39             border-left: 20px solid pink;
     40         }
     41         div li a:link,div li a:visited{
     42             background-color: #F0F0F0;
     43             color: #461737;
     44         }
     45         div li a:hover{
     46             background-color: green;
     47             color: gray;
     48         }
     49         div li a:active{
     50             background-color: pink;
     51         }
     52         #left{
     53         float:left;
     54         }
     55         #right{
     56         height:400px;
     57         width:1100px;
     58         float:left;
     59         }
     60         #inp{
     61         float:left;
     62         height:400px;
     63         width:1202px;
     64         }
     65         .btn{
     66         float:left;
     67         }
     68           table
     69         {
     70             width:1100px;
     71             height:500px;
     72             border-collapse: collapse;
     73             margin: 0 auto;
     74             text-align: center;
     75         }
     76         table td, table th
     77         {
     78             border: 1px solid #cad9ea;
     79             color: #666;
     80             height: 30px;
     81         }
     82         table thead th
     83         {
     84             background-color: #CCE8EB;
     85             width: 100px;
     86         }
     87         table tr:nth-child(odd)
     88         {
     89             background: #fff;
     90         }
     91         table tr:nth-child(even)
     92         {
     93             background: #F5FAFA;
     94         }
     95                 
     96     button { /* 按钮美化 */
     97     width: 270px; /* 宽度 */
     98     height: 40px; /* 高度 */
     99     border-width: 0px; /* 边框宽度 */
    100     border-radius: 3px; /* 边框半径 */
    101     background: #1E90FF; /* 背景颜色 */
    102     cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
    103     outline: none; /* 不显示轮廓线 */
    104     font-family: Microsoft YaHei; /* 设置字体 */
    105     color: white; /* 字体颜色 */
    106     font-size: 17px; /* 字体大小 */
    107 }
    108     button:hover { /* 鼠标移入按钮范围时改变颜色 */
    109     background: #5599FF;
    110 
    111 </style>
    112 <script>
    113 function ForDetail(id){
    114     window.location.href="ShowStudent?id="+id;
    115 }
    116 
    117 function Borrow(id){
    118     var sentence=confirm("是否确认删除该选课?");
    119     if(sentence==true)
    120     window.location.href="DeleteMyClass?id="+id;
    121 }
    122 
    123 
    124 </script>
    125 </head>
    126 <body onload="Onload()">
    127     <div id="d1">选课系统</div>
    128     <div id="left">
    129 <ul>
    130     <li class="headd"><a href="#" onclick="fresh()">|REFESH|</a></li>
    131     <%if(((String)session.getAttribute("usertype")).equals("root")){ %>
    132     <li><a href="StudentIn.jsp">学生信息录入</a></li>
    133     <li><a href="TeacherIn.jsp">教师信息录入</a></li>
    134     <li><a href="AddUser.jsp">用户录入</a></li>
    135     <li><a href="ShowStudent">学生信息</a></li>
    136     <li><a href="ShowTeacher">教师信息</a></li>
    137     <li><a href="ShowUser">用户信息</a></li>
    138     <li><a href="AnalyseSum.jsp">统计学生信息</a></li>
    139     <%}else if(((String)session.getAttribute("usertype")).equals("stu")){%>
    140     <li><a href="ShowMySession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    141     <li><a href="ShowClass">选课</a></li>
    142     <li><a href="HaveSelected">已选课</a>
    143     <%}else if(((String)session.getAttribute("usertype")).equals("tch")){ %>
    144     <li><a href="ShowTeaSession?id=<%=session.getAttribute("userid")%>">我的信息</a></li>
    145     <li><a href="AddClass.jsp">添加课程</a></li>
    146     <li><a href="ShowTeaClas">自己的课程</a></li>
    147     <%} %>    
    148     <li><a href="UpdatePassword.jsp">修改密码</a></li>
    149 </ul>
    150 </div>
    151 <div id="right">
    152 <table>
    153 <c:forEach items="${list}" var="list">
    154 <tr>
    155 <td>课程编号:${list.id}</td>
    156 <td onclick="ForDetail(${list.id})">课程名称:${list.name}</td>
    157 <td>选课人数:${list.nownumber}</td>
    158 <td>课程容量: ${list.number}</td>
    159 <td><button onclick="Borrow(${list.id})">删除课程</button></td>
    160 </c:forEach>
    161 </table>
    162 </div>
    163 </body>
    164 </html>
    HavenSelect.jsp
     1 package p1;
     2 
     3 import java.io.IOException;
     4 import java.sql.Connection;
     5 import java.sql.ResultSet;
     6 import java.sql.SQLException;
     7 import java.sql.Statement;
     8 
     9 import javax.servlet.ServletException;
    10 import javax.servlet.annotation.WebServlet;
    11 import javax.servlet.http.HttpServlet;
    12 import javax.servlet.http.HttpServletRequest;
    13 import javax.servlet.http.HttpServletResponse;
    14 @WebServlet("/DeleteMyClass")
    15 public class DeleteMyClass extends HttpServlet {
    16     private static final long serialVersionUID = 1L;
    17     public DeleteMyClass() {
    18         super();
    19     }
    20     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    21         String id=request.getParameter("id");
    22         String userid=(String)request.getSession().getAttribute("userid");
    23         Link l=new Link();
    24         try {
    25             Connection con=l.lin("Class_Select");
    26             Statement stmt=con.createStatement();
    27             String s="select * from Clas where id='"+id+"'";
    28             ResultSet rsst=stmt.executeQuery(s);
    29             rsst.next();
    30             String asker=rsst.getString("asker");
    31             String ask="_".replaceAll(asker,userid);
    32             rsst.close();
    33             s="update Clas set asker='"+ask+"',nownumber=nownumber-1 where id='"+id+"'";
    34             stmt.executeUpdate(s);
    35             stmt.close();
    36             con.close();
    37         } catch (SQLException e) {
    38             // TODO Auto-generated catch block
    39             e.printStackTrace();
    40         }
    41         request.getSession().setAttribute("message", "删除成功!");
    42         request.getRequestDispatcher("HaveSelected").forward(request, response);
    43     }
    44     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    45         // TODO Auto-generated method stub
    46         doGet(request, response);
    47     }
    48 
    49 }
    DeleteMyClass.java
  • 相关阅读:
    zepto引用touch模块后,click失效
    cocos2dx中setContentSize与setDimensions在设置label显示区域上的区别
    convertToNodeSpace 与 convertToWorldSpace 的使用
    quick(3.2) UIListView扩展
    quick-cocos2d-x 游戏开发——StateMachine 状态机
    Lua学习笔记之字符串及模式匹配
    cocos2dx-3.x事件分发机制
    cocos2dx-Lua与Object的通讯机制
    cocos2dx-Lua与Java通讯机制
    Quick-cocos2dx容器层的使用
  • 原文地址:https://www.cnblogs.com/XiaoGao128/p/12191510.html
Copyright © 2011-2022 走看看