軟件工程學習進度第五週暨暑期學習進度之第五週彙總

---恢復內容開始---javascript

本週只作了一件事,就是學生信息管理系統。css

首先,信息管理系統的學籍信息的獲取,是基於Python爬蟲爬取的中國全部省市名及對應的的身份證號前六位,並經過身份證號生成相關的家庭住址、高考考號、生日、省份、城市信息,以及經過之前建立的數據表中的姓名、性別、學號、學院、專業、班級相關聯生成護照姓名、年級、行政班級、行政學院等學籍信息,使信息顯得極其逼真。html

用於生成學籍的Python源碼以下:java

  1 from xpinyin import Pinyin
  2 from pymysql import *
  3 import random
  4 import time
  5 from bs4 import BeautifulSoup
  6 from urllib3 import *
  7 from re import *
  8 import json
  9 
 10 num_list = []
 11 address_list = []
 12 
 13 def regiun():
 14     #爬蟲爬取身份證前六位及對應地址
 15 
 16     url = "http://www.360doc.com/content/12/1010/21/156610_240728293.shtml"
 17     http = PoolManager()
 18     html = http.request('GET', url)
 19     htmlstr = html.data.decode('utf-8')
 20     bs = BeautifulSoup(htmlstr, 'lxml')
 21     p_list = bs.findAll('p', {
 22         'style': "TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; BACKGROUND: white; mso-pagination: widow-orphan"})
 23     index = 1
 24     for i in p_list:
 25         if index <= 8:
 26             index = index + 1
 27             continue
 28         str = i.text
 29         str_list = str.split(" ")
 30         num_list.append(str_list[0])
 31         address_list.append(str_list[1])
 32         first = random.choice(num_list)
 33     return first
 34 
 35 def year():
 36     now = time.strftime('%Y')
 37     second = random.randint(1995,int(now)-18)
 38     age = int(now) - second
 39     return second
 40 
 41 def month():
 42     three = random.randint(1,12)
 43     #月份小於10如下,前面加上0填充
 44     if three < 10:
 45         three = '0' + str(three)
 46         return three
 47     else:
 48         return three
 49 
 50 def day():
 51     four = random.randint(1,31)
 52     #日期小於10如下,前面加上0填充
 53     if four < 10:
 54         four = '0' + str(four)
 55         return four
 56     else:
 57         return four
 58 
 59 def randoms():
 60     #後面序號低於相應位數,前面加上0填充
 61     five = random.randint(1,9999)
 62     if five < 10:
 63         five = '000' + str(five)
 64         return five
 65     elif 10 < five < 100:
 66         five = '00' + str(five)
 67         return five
 68     elif 100 < five < 1000:
 69         five = '0' + str(five)
 70         return five
 71     else:
 72         return five
 73 
 74 def Random_ID_number():
 75     first = regiun()
 76     second = year()
 77     three = month()
 78     four = day()
 79     last = randoms()
 80     IDcard = str(first)+str(second)+str(three)+str(four)+str(last)
 81     print(IDcard)
 82     return IDcard
 83 
 84 #根據身份證號生成生日
 85 def get_birthday(ID_number):
 86     year=ID_number[6:10]
 87     month=ID_number[10:12]
 88     day=ID_number[12:14]
 89     birthday=year+'-'+month+'-'+day
 90     print(birthday)
 91     return birthday
 92 
 93 # 根據學院和年級生成校區信息,在此只設定大一土木在南校區
 94 def get_campus(agency,grade):
 95     now = time.strftime('%Y')
 96     if agency == "土木工程學院" and int(now)-int(grade) == 0:
 97         print("南校區")
 98         return "南校區"
 99     else:
100         print("本部")
101         return "本部"
102 
103 # 根據身份證號生成學生籍貫
104 def get_native_place(ID_number):
105     print(address_list[num_list.index(ID_number[0:6])])
106     return address_list[num_list.index(ID_number[0:6])]
107 
108 # 隨機生成民族
109 def Random_nation():
110     nation_list=['漢族','回族','苗族','壯族']
111     print(nation_list[random.randint(0,3)])
112     return nation_list[random.randint(0,3)]
113 
114 # 根據身份證號獲取高考考號
115 def get_exam_number(ID_number,grade):
116     year_final=grade[2:4]
117     six=ID_number[0:6]
118     year_enter=str(int(year_final)-3)
119     tail=str(randoms())
120     exam_num=year_final+six+year_enter+tail
121     print(exam_num)
122     return exam_num
123 
124 def get_address(str):
125     if str.find("") != -1:
126         province = str[0:str.find("") + 1]
127         if str.find("自治州") != -1:
128             city = str[str.find("") + 1:str.find("自治州") + 3]
129         elif str.find("") != -1 and str.find("") != -1 and str.find("") < str.find(""):
130             city = str[str.find("") + 1:str.find("") + 1]
131         elif str.find("") != -1 and str.find("") != -1 and str.find("") > str.find(""):
132             city = str[str.find("") + 1:str.find("") + 1]
133         elif str.find("") != -1 and str.find("") == -1:
134             city = str[str.find("") + 1:str.find("") + 1]
135         elif str.find("") == -1 and str.find("") != -1:
136             city = str[str.find("") + 1:str.find("") + 1]
137         else:
138             city=province
139     elif str.find("自治區"):
140         province = str[0:str.find("自治區") + 3]
141         if str.find("") != -1:
142             city = str[str.find("自治區") + 3:str.find("") + 1]
143         elif str.find("") != -1:
144             city = str[str.find("自治區") + 3:str.find("") + 1]
145         else:
146             city=province
147     elif str.find("") != -1:
148         province = str[0:str.find("") + 1]
149         city = str[0:str.find("") + 1]
150     address=[province,city]
151     return  address
152 
153 def get_province(ID_number):
154     print(get_address(address_list[num_list.index(ID_number[0:6])])[0])
155     return get_address(address_list[num_list.index(ID_number[0:6])])[0]
156 
157 def get_city(ID_number):
158     print(get_address(address_list[num_list.index(ID_number[0:6])])[1])
159     return get_address(address_list[num_list.index(ID_number[0:6])])[1]
160 
161 # 隨機生成聯繫電話
162 def Random_phone():
163     head_list=['151','137','136','172','157']
164     else_num=""
165     for i in range(0,7):
166         else_num=else_num+str(random.randint(0,9))
167     print(head_list[random.randint(0,4)]+else_num)
168     return head_list[random.randint(0,4)]+else_num
169 
170 # 根據城市名稱隨機生成高中學校名
171 def Random_school(city):
172     index=['','','','','','','','']
173     print(city+""+index[random.randint(0,7)]+"中學")
174     return city+""+index[random.randint(0,7)]+"中學"
175 
176 # 隨機生成考生類別(農村應屆或城市應屆)
177 def Random_std_class():
178     list=['農村應屆','城市應屆']
179     print(list[random.randint(0,1)])
180     return list[random.randint(0,1)]
181 
182 # 判斷理工科仍是文科
183 def get_exam_type(agency):
184     if agency=="文法學院" or agency=="馬克思主義學院":
185         return "普文"
186     else:
187         return "理工"
188 
189 
190 try:
191     db = connect(host='localhost', port=3306, user='root', password='010218', db='people_information_db')
192     print("數據庫鏈接成功")
193 
194 except Exception as e:
195     print(e)
196 
197 inquireSql='''
198     select * from std_information
199 '''
200 newtable='''
201     create table std_status(
202         id varchar(10) primary key not null,
203         name varchar(10) not null,
204         passport_name varchar(20) not null,
205         sex varchar(10) not null,
206         birthday varchar(10) not null,
207         state varchar(10) not null,
208         agency varchar(10) not null,
209         grade varchar(5) not null,
210         major varchar(10) not null,
211         class_num varchar(10) not null,
212         national_major varchar(10) not null,
213         campus varchar(10) not null,
214         administrate_agency varchar(10) not null,
215         administrate_class varchar(10) not null,
216         native_place varchar(30) not null,
217         nation varchar(10) not null,
218         politics_status varchar(15) not null,
219         ID_number varchar(18) not null,
220         exam_number varchar(15) not null,
221         transport_place varchar(20) not null,
222         province varchar(10) not null,
223         city varchar(10) not null,
224         phone varchar(11) not null,
225         address varchar(30) not null,
226         student_origin varchar(10) not null,
227         graduation_school varchar(20) not null,
228         exam_std_class varchar(10) not null,
229         admit_form varchar(10) not null,
230         admit_origin varchar(10) not null,
231         exam_type varchar(10) not null,
232         double_degree varchar(20),
233         std_label varchar(10) not null,
234         special_remark varchar(50)
235     )
236 '''
237 
238 cursor=db.cursor()
239 try:
240     pin=Pinyin()
241     cursor.execute(newtable)
242     cursor.execute(inquireSql)
243     results=cursor.fetchall()
244     for row in results:
245         id=row[0]
246         name=row[1]
247         passport_name=pin.get_pinyin(row[1],' ').upper()
248         sex=row[2]
249         ID_number=Random_ID_number()
250         birthday=get_birthday(ID_number)
251         state="有學籍 在讀"
252         agency=row[3]
253         grade=id[0:4]
254         major=row[4]
255         class_num=row[5]
256         nation_major=major
257         campus=get_campus(agency,grade)
258         administrate_agency=agency
259         administrate_class=class_num
260         native_place=get_native_place(ID_number)
261         nation=Random_nation()
262         politics_status="中國共產主義青年團團員"
263         exam_number=get_exam_number(ID_number,grade)
264         province=get_province(ID_number)
265         city=get_city(ID_number)
266         address=province+city
267         phone=Random_phone()
268         transport_place="石家莊--"+address
269         student_origin=province
270         graduation_school=Random_school(city)
271         exam_std_class=Random_std_class()
272         admit_form="統招"
273         admit_origin=province
274         exam_type=get_exam_type(agency)
275         double_degree=""
276         std_label="普通學生"
277         special_remark=""
278 
279 
280         insert_information = '''
281             insert into std_status(id,name,passport_name,sex,birthday,state,agency,grade,major,class_num,national_major,
282             campus,administrate_agency,administrate_class,native_place,nation,politics_status,ID_number,exam_number,transport_place,
283             province,city,phone,address,student_origin,graduation_school,exam_std_class,admit_form,admit_origin,exam_type,
284             double_degree,std_label,special_remark) values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',
285              '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')
286         '''%(id,name,passport_name,sex,birthday,state,agency,grade,major,class_num,nation_major,campus,administrate_agency,administrate_class,
287              native_place,nation,politics_status,ID_number,exam_number,transport_place,province,city,phone,address,student_origin,graduation_school,
288              exam_std_class,admit_form,admit_origin,exam_type,double_degree,std_label,special_remark)
289         cursor.execute(insert_information)
290         db.commit()
291 except Exception as e:
292     print(e)

該程序是基於已經存在的數據表std_information實現的,數據庫結構以下:mysql

接下來展現學生信息管理系統的文件結構:jquery

因爲以前發過的部分頁面在後續進度中有部分修改,在這裏從新上傳所有頁面代碼。css3

登陸頁面:web

  1 <%@page import="com.stumag.util.DBUtil"%>
  2 <%@page import="com.mysql.cj.jdbc.Driver"%>
  3 <%@page import="java.sql.Statement"%>
  4 <%@page import="java.sql.ResultSet"%>
  5 <%@page import="javax.naming.spi.DirStateFactory.Result"%>
  6 <%@page import="java.sql.DriverManager"%>
  7 <%@page import="java.sql.Connection"%>
  8 <%@ page language="java" contentType="text/html; charset=utf-8"
  9     pageEncoding="utf-8"%>
 10 <!DOCTYPE html>
 11 <html>
 12 <head>
 13 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 14 <title>小趙的學生信息管理系統</title>
 15 <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
 16 <style>
 17     *{
 18     margin:0;
 19     padding:0;
 20     }
 21     .wrap {    
 22     background-image: url(images/signin.jpg);
 23     background-size: cover;    
 24     background-repeat: no-repeat;    
 25     background-position: center center;    
 26     position: relative;
 27     height: 719px;    
 28     width: 100;    
 29     }
 30 
 31     .head {
 32     background-color: #66CCCC;
 33     text-align: center;
 34     position: relative;
 35     height: 100px;
 36     width: 100;
 37     text-shadow: 5px 5px 4px Black;
 38     }
 39     .foot {
 40     width: 100;
 41     height:200px;
 42     background-color:#CC9933;
 43     position: relative;
 44     }
 45     .wrap .logcontainer { 
 46     position: absolute;
 47     background-color: #FFFFFF;
 48     top: 20%;
 49     right: 15%;
 50     height: 408px;
 51     width: 368px; 
 52     }
 53     .logbt a input {
 54     width: 100%;
 55     height: 45px;
 56     background-color: #ee7700;
 57     border: none;
 58     color: white;
 59     font-size: 18px;
 60     }
 61     .logcontainer .logD.logDtip .p1 {    
 62     display: inline-block;    
 63     font-size: 28px;    
 64     margin-top: 30px;    
 65     width: 86%;
 66     }
 67     .wrap .logcontainer .logD.logDtip {    
 68     width: 86%;    
 69     border-bottom: 1px solid #ee7700;
 70     margin-bottom: 60px;
 71     margin-top: 0px;    
 72     margin-right: auto;    
 73     margin-left: auto;
 74     }
 75     .logcontainer .lgD img {    
 76     position: absolute;
 77     top: 12px;    
 78     left: 8px;
 79     }
 80     .logcontainer .lgD input {    
 81     width: 100%;    
 82     height: 42px;    
 83     text-indent: 2.5rem;
 84     }
 85     .wrap .logcontainer .lgD {    
 86     width: 86%;    
 87     position: relative;    
 88     margin-bottom: 30px;    
 89     margin-top: 30px;    
 90     margin-right: auto;    
 91     margin-left: auto;
 92     }
 93     .wrap .logcontainer .logbt {    
 94     width: 86%;    
 95     margin-top: 0px;    
 96     margin-right: auto;    
 97     margin-bottom: 20px;    
 98     margin-left: auto;
 99     }
100     .wrap .logcontainer .signin{
101     width:40%;
102     margin-top:20px;
103     margin-bottom:0px;
104     margin-left:auto;
105     margin-right:20px;
106     }
107     .title {    
108     font-family: "宋體";    
109     color: #FFFFFF;    
110     position: absolute;    
111     top: 50%;    
112     left: 50%;    
113     transform: translate(-50%, -50%);  /* 使用css3的transform來實現 */    
114     font-size: 36px;    height: 40px;    
115     width: 30%;
116     } 
117     .power {    
118     font-family: "宋體";
119     color: #FFFFFF;    
120     position: absolute;    
121     top: 50%;    
122     left: 50%;    
123     transform: translate(-50%, -50%);  
124     height: 60px;    
125     width: 40%;    
126     text-align:center;
127     }     
128     .foot .power .information {    
129     width: 100%;    
130     height: 24px;    
131     position: relative;
132     }
133     
134     
135     .foot .power p {    
136     height: 24px;    
137     width: 100%;
138     }
139     .wrap .logcontainer .logbt #loginbtn{
140     border-radius:8px;
141     }
142     .wrap .logcontainer{
143     border-radius:5px;
144     border:none;
145     background-color:rgba(232,232,232,0.5) ;
146     }
147 </style>
148 </head>
149 <body>
150     
151     <div class="head" id="head">
152       <div class="title">小趙的學生信息管理系統</div>
153     </div>
154 
155     <div class="wrap" id="wrap">
156         <div class="logcontainer">
157         <!-- 頭部提示信息 -->            
158             <div class="logD logDtip">                
159             <p class="p1">登陸</p>            
160             </div>        
161             <!-- 輸入框 -->
162             <form action="login_do" method="post">
163                 <div class="lgD">                
164                 <img src="images/icon.png" width="20" height="20"/>
165                 <input class="logDinput" id="username" name="username" type="text" placeholder="輸入用戶名" />
166                 </div>        
167                 
168                 <div class="lgD">                
169                 <img src="images/mima.png" width="20" height="20" alt=""/>                
170                 <input class="logDinput" id="password" name="password" type="password" placeholder="輸入用戶密碼" />            
171                 </div>
172                     
173                 <div class="logbt">                
174                 <a id="loginlink" target="_self"><input type="submit" id="loginbtn" value="登 錄"/></a>            
175                 </div>
176             </form>
177             
178             <div class="signin">
179                 <a href="sign.jsp">沒有帳號?註冊一個</a>
180             </div>        
181         </div>
182     </div>
183     <div class="foot" id="foot">  
184         <div class="power">    
185             Copyright © 2019 All Rights Reserved.   
186             <div class="information">        
187             <span>聯繫郵箱:1927006283@qq.com</span>    
188             </div>        
189             <div class="information">        
190             <span>聯繫地址:石家莊鐵道大學</span>    
191             </div>          
192             <div class="information">      
193             <span>聯繫電話:15716888392</span>    
194             </div>    
195         </div>    
196     </div>
197 </body>
198 </html>
View Code

處理登陸請求的servlet:sql

 1 package com.stumag.servlet;
 2 
 3 import java.io.IOException;
 4 import javax.servlet.ServletException;
 5 import javax.servlet.annotation.WebServlet;
 6 import javax.servlet.http.HttpServlet;
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpServletResponse;
 9 
10 import com.stumag.util.DBUtil;
11 
12 /**
13  * Servlet implementation class login_do
14  */
15 @WebServlet("/login_do")
16 public class login_do extends HttpServlet {
17     private static final long serialVersionUID = 1L;
18     
19     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
20         // TODO Auto-generated method stub
21         String username=request.getParameter("username");
22         
23         String password=request.getParameter("password");
24         
25         if(DBUtil.isExist(username, password))
26         {
27             request.getRequestDispatcher("mainpage.jsp").forward(request, response);
28         }
29         else
30         {
31             request.getRequestDispatcher("login.jsp").forward(request,response);
32         }
33     }
34 
35 }
View Code

 

效果:數據庫

註冊頁面:

  1 <%@ page language="java" contentType="text/html; charset=GB18030"
  2     pageEncoding="GB18030"%>
  3 <!DOCTYPE html>
  4 <html>
  5 <head>
  6 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
  7 <title>用戶註冊</title>
  8 <style>
  9     *{
 10     margin=0;
 11     padding=0;
 12     }
 13     .head{
 14     width:100;
 15     height:100px;
 16     text-align:center;
 17     background-color:#66CCCC;
 18     position:relative;
 19     text-shadow: 5px 5px 4px Black;
 20     }
 21     .wrap{
 22     width:100;
 23     height:768px;
 24     background-image:url(images/signin.jpg);
 25     background-size:cover;
 26     background-repeat:no-repeat;
 27     background-position:center center;
 28     position:relative;
 29     }
 30     .foot {
 31     width: 100;
 32     height:200px;
 33     background-color:#CC9933;
 34     position: relative;
 35     }
 36     .title {    
 37     font-family: "宋體";    
 38     color: #FFFFFF;    
 39     position: absolute;    
 40     transform: translate(-50%, -50%);
 41     font-size: 36px;    
 42     height: 40px;    
 43     width: 30%;
 44     top: 50%;    
 45     left: 50%;    
 46     } 
 47     .power {    
 48     font-family: "宋體";
 49     color: #FFFFFF;    
 50     position: absolute;    
 51     top: 50%;    
 52     left: 50%;    
 53     transform: translate(-50%, -50%);  
 54     height: 60px;    
 55     width: 40%;    
 56     text-align:center;
 57     }     
 58     .foot .power p {    
 59     height: 24px;    
 60     width: 100%;
 61     }
 62     .foot .power .information {    
 63     width: 100%;    
 64     height: 24px;    
 65     position: relative;
 66     }
 67     .container{
 68     width: 400px;
 69     height: 100;
 70     padding: 13px;
 71     position: absolute;
 72     left: 50%;
 73     top: 40%;
 74     margin-left: -200px;    
 75     margin-top: -200px;     
 76     background-color: rgba(240, 255, 255, 0.5);     
 77     border-radius: 10px;
 78     text-align: center;
 79     }
 80     .input_hint{
 81     width:30%;
 82     height:20px;
 83     position:relative;
 84     margin-top:10px;
 85     margin-bottom:0px;
 86     margin-left:0px;
 87     margin-right:auto;
 88     font-size:20sp;
 89     }
 90     .wrap .container .signintext{    
 91     width: 86%;    
 92     border-bottom: 1px solid #ee7700;
 93     margin-bottom: 60px;
 94     margin-top: 0px;    
 95     margin-right: auto;    
 96     margin-left: auto;
 97     }
 98     .wrap .container .signintext .signinp{
 99     display: inline-block;
100     font-size: 28px;
101     width:86%;
102     margin-top: 30px;
103     }
104     .wrap .container .user{
105     position:relative;
106     margin-top:20px;
107     margin-bottom:20px;
108     margin-left:auto;
109     margin-right:auto;
110     }
111     div div table td{
112     padding:10px;
113     }
114     .wrap .container .user .signinput{
115     width:70%;
116     height:35px;
117     }
118     .wrap .container .user .signinput .i_input{
119     width:100%;
120     height:100%;
121     border-radius:5px;
122     border:none;
123     background-color:rgba(232,232,232,0.5) ;
124     }
125     .wrap .container .signbtn{
126     width: 80%;
127     height: 45px;
128     background-color: #ee7700;
129     border: none;
130     color: white;
131     margin-top:20px;
132     margin-bottom:10px;
133     font-size: 18px;
134     border-radius:8px;
135     }
136 </style>
137 
138 </head>
139 <body>
140     <div id="header" class="head">
141         <div class="title">小趙的學生信息管理系統</div>
142     </div>
143     <div class="wrap" id="wrap">
144         <div id="container" class="container">
145             <div class="signintext">
146                 <p class="signinp">註冊</p>
147             </div>
148             <form action="signin_do" method="post">
149                 <table class="user">
150                 
151                     <tr class="ID uesr">
152                     <td class="input_hint"><label>學 /工號:</label></td>
153                     <td class="signinput"><input class="i_input" name="ID" type="text" maxlength="20" size="20" placeholder="請輸入學號/工號"></td>
154                     </tr>
155                     
156                     <tr class="usrn user">
157                     <td class="input_hint"><label>用 戶 名:</label></td>
158                     <td class="signinput"><input class="i_input" name="username" type="text" maxlength="20" size="20" placeholder="請輸入用戶名"></td>
159                     </tr>
160                     
161                     <tr class="pwd user">
162                     <td class="input_hint"><label>密&#160;&#160;&#160;&#160;&#160;碼:</label></td>
163                     <td class="signinput"><input class="i_input" name="password" type="password" maxlength="20" size="20" placeholder="請輸入密碼"></td>
164                     </tr>
165                     
166                     <tr class="repwd user">
167                     <td class="input_hint"><label>確認密碼:</label></td>
168                     <td class="signinput"><input class="i_input" name="againpwd" type="password" maxlength="20" size="20" placeholder="請再次輸入密碼"></td>
169                     </tr>
170                     
171                     <tr class="email user">
172                     <td class="input_hint"><label>電子郵箱:</label></td>
173                     <td class="signinput"><input class="i_input" name="email" type="email" placeholder="請輸入郵箱地址" onclick="onclick()"></td>
174                     </tr>
175                     
176                     <tr><td colspan="2"><input id="signbtn" class="signbtn" type="submit" value="註冊"></td></tr>
177                 
178                 </table>
179             </form>
180         </div>
181     </div>
182     <div class="foot" id="foot">  
183         <div class="power">    
184             Copyright © 2019 All Rights Reserved.   
185             <div class="information">
186             <span>聯繫郵箱:1927006283@qq.com</span>    
187             </div>        
188             <div class="information">        
189             <span>聯繫地址:石家莊鐵道大學</span>    
190             </div>          
191             <div class="information">      
192             <span>聯繫電話:15716888392</span>    
193             </div>    
194         </div>    
195     </div>
196 </body>
197 </html>
View Code

處理註冊請求的servlet:

 1 package com.stumag.servlet;
 2 
 3 import java.io.IOException;
 4 import javax.servlet.ServletException;
 5 import javax.servlet.annotation.WebServlet;
 6 import javax.servlet.http.HttpServlet;
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpServletResponse;
 9 
10 import com.stumag.util.DBUtil;
11 
12 /**
13  * Servlet implementation class signin_do
14  */
15 @WebServlet("/signin_do")
16 public class signin_do extends HttpServlet {
17     private static final long serialVersionUID = 1L;
18     
19     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
20         // TODO Auto-generated method stub
21         String ID=request.getParameter("ID");
22         String username=request.getParameter("username");
23         String password=request.getParameter("password");
24         String againpwd=request.getParameter("againpwd");
25         String email=request.getParameter("email");
26         if(againpwd.equals(password)==false)
27         {
28             System.out.println("兩次密碼輸入不一致");
29             request.getRequestDispatcher("signin.jsp").forward(request, response);
30         }
31         else
32         {
33             if(DBUtil.query_idnothad(ID)&&DBUtil.query_usernothad(username))
34             {
35                 DBUtil.addUser(ID, username, password, email);
36                 request.getRequestDispatcher("login.jsp").forward(request, response);
37                 System.out.println("註冊成功");
38             }
39             else
40             {
41                 System.out.println("id或用戶名已存在");
42                 request.getRequestDispatcher("sign.jsp").forward(request, response);
43             }
44         }
45     }
46 
47 }
View Code

 

效果:

登陸首頁:

  1 <%@page import="com.mysql.cj.jdbc.Driver"%>
  2 <%@page import="java.sql.Statement"%>
  3 <%@page import="java.sql.ResultSet"%>
  4 <%@page import="javax.naming.spi.DirStateFactory.Result"%>
  5 <%@page import="java.sql.DriverManager"%>
  6 <%@page import="java.sql.Connection"%>
  7 <%@ page language="java" contentType="text/html; charset=GB18030"
  8     pageEncoding="GB18030"%>
  9 <!DOCTYPE html>
 10 <html>
 11 <head>
 12 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
 13 <script type="text/javascript" src="jquery.min.js"></script>
 14 <script type="text/javascript" src="jquery.bumpytext.packed.js"></script>
 15 <script type="text/javascript" src="easying.js"></script>
 16 <script type="text/javascript">
 17     //<![CDATA[
 18     $(document).ready(function() {
 19         $('p#example').bumpyText();
 20     });            //]]>
 21     
 22     $(document).ready(function() {
 23     }); 
 24 </script>
 25 <title>首頁</title>
 26 
 27 <style>
 28     *{
 29         margin:0px;
 30         padding:0px;
 31     }
 32     .head {
 33     background-color: #66CCCC;
 34     text-align: center;
 35     position: relative;
 36     height: 100px;
 37     width: 100;
 38     text-shadow: 5px 5px 4px Black;
 39     }
 40     .wrap{
 41     width:100;
 42     height:764px;
 43     }
 44     .wrap .na{
 45     position:relative;
 46     height:764px;
 47     width:15%;
 48     float:left;
 49     background-size:cover;
 50     background-repeat:no-repeat;
 51     }
 52     .wrap .newsshow{
 53     position:relative;
 54     height:764px;
 55     width:85%;
 56     float:right;
 57     text-align:center;
 58     background-size:cover;
 59     overflow-y :auto;
 60     }
 61     .foot {
 62     width: 100;
 63     height:200px;
 64     background-color:#CC9933;
 65     position: relative;
 66     text-align:center;
 67     }
 68     .title {    
 69     font-family: "宋體";    
 70     color: #FFFFFF;    
 71     position: absolute;    
 72     top: 50%;    
 73     left: 50%;    
 74     transform: translate(-50%, -50%);  /* 使用css3的transform來實現 */    
 75     font-size: 36px;    
 76     height: 40px;    
 77     width: 30%;
 78     } 
 79     .power {    
 80     font-family: "宋體";
 81     color: #FFFFFF;    
 82     position: absolute;    
 83     top: 50%;
 84     left: 50%;    
 85     transform: translate(-50%, -50%);  
 86     height: 60px;    
 87     width: 40%;    
 88     align-content:center;
 89     }     
 90     .foot .power .information {    
 91     width: 100%;    
 92     height: 24px;    
 93     position: relative;
 94     }
 95     .foot .power p {    
 96     height: 24px;    
 97     width: 100%;
 98     }
 99     .wrap .nav .navbar{
100     text-align:center;
101     text-size:10px;
102     }
103     .nav { float: left; clear: both; width: 15%; margin: auto; height:764px; background: #eee; }
104     .nav ul { list-style: none; margin: 0px; padding: 0px; }
105     .nav li { float: none; width: 100%; }
106     .nav li a { display: block; width: 100%; padding: 20px; border-left: 5px solid; position: relative; z-index: 2; text-decoration: none; color: #444; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box;font-size:14px; }
107     .nav li a:hover { border-bottom: 0px; color: #fff; }
108     .nav li:first-child a { border-left: 10px solid #3498db; }
109     .nav li:nth-child(2) a { border-left: 10px solid #ffd071; }
110     .nav li:nth-child(3) a { border-left: 10px solid #f0776c; }
111     .nav li:nth-child(4) a { border-left: 10px solid #9370db; }
112     .nav li:nth-child(5) a { border-left: 10px solid #9acd32; }
113     .nav li:nth-child(6) a { border-left: 10px solid #888888; }
114     .nav li:last-child a { border-left: 10px solid #1abc9c; }
115     .nav li a:after { content: ""; height: 100%; left: 0; top: 0; width: 0px; position: absolute; transition: all 0.3s ease 0s; -webkit-transition: all 0.3s ease 0s; z-index: -1; }
116     .nav li a:hover:after { width: 100%; }
117     .nav li:first-child a:after { background: #3498db; }
118     .nav li:nth-child(2) a:after { background: #ffd071; }
119     .nav li:nth-child(3) a:after { background: #f0776c; }
120     .nav li:nth-child(4) a:after { background: #9370db; }
121     .nav li:nth-child(5) a:after { background: #9acd32; }
122     .nav li:nth-child(6) a:after { background: #888888; }
123     .nav li:last-child a:after { background: #1abc9c; }
124 
125     .nav li:first-child a{ background: #3498db; }
126     
127     .clearfix {display: inline-block;}
128     .clearfix {display: block;}
129     #example{margin-top:-40px;}
130     .bumpy-char {
131     line-height: 3.4em;
132     position: relative;
133     }
134     
135 
136     .wrap .newsshow .titleimg{
137     width:100%;
138     height:170px;
139     background-repeat:no-repeat;
140     background-size:100% 100%;
141     position:relative;
142     background-image:url(images/stdtitle.jpg);
143     }
144     
145     .wrap .newsshow .newstitle{
146     padding-top:10px;
147     width:100%;
148     height:30px;
149     font-family:"宋體";
150     font-size:20px;
151     text-align:center;
152     position:relative;
153     }
154     
155     .wrap .newsshow .newslist{
156     width:50%;
157     height:100%;
158     float:left;
159     position:relative;
160     background-color: rgba(200, 200, 200, 0.5);     
161     border-radius: 10px 0px 0px 10px;
162     }
163     .wrap .newsshow .noticelist{
164     width:50%;
165     height:100%;
166     float:right;
167     position:relative;
168     background-color: rgba(200, 200, 200, 0.5);     
169     border-radius: 0px 10px 10px 0px;
170     }
171     
172     .wrap .newsshow .newslist ul li{
173     padding:10px 50px;
174     text-align:left;
175     border-bottom: 1px solid #ee7700;
176     }
177     .wrap .newsshow .noticelist ul li{
178     padding:10px 50px;
179     text-align:left;
180     border-bottom: 1px solid #ee7700;
181     }
182     .wrap .newsshow .newslist ul li a{
183     text-decoration:none;
184     }
185     .wrap .newsshow .noticelist ul li a{
186     text-decoration:none;
187     }
188     
189 </style>
190 
191 </head>
192 <body>
193     <%! 
194         String str_newstitle[]=new String[20];
195         String str_noticetitle[]=new String[20];
196         String str_newshref[]=new String[20];
197         String str_noticehref[]=new String[20];
198         String str_more[]=new String[2];
199     %>
200     <%
201         Connection con=null;
202         Statement stmt=null;
203         ResultSet rs_news=null;
204         ResultSet rs_notice=null;
205         ResultSet rs_more=null;
206         try{
207             Class.forName("com.mysql.cj.jdbc.Driver");
208             String url="jdbc:mysql://localhost:3306/people_information_db?useUnicode=true&characterEncoding=GB18030&useSSL=false&serverTimezone=GMT";
209             String username="root";
210             String password="010218";
211             con=DriverManager.getConnection(url, username, password);
212             if(con!=null)
213             {
214                 stmt=con.createStatement();
215                 rs_news=stmt.executeQuery("select * from std_news");
216                 int i=0;
217                 while(rs_news.next())
218                 {
219                     str_newstitle[i]=rs_news.getString(1);
220                     str_newshref[i]=rs_news.getString(2);
221                     i++;
222                 }
223                 rs_notice=stmt.executeQuery("select * from std_notice");
224                 i=0;
225                 while(rs_notice.next())
226                 {
227                     str_noticetitle[i]=rs_notice.getString(1);
228                     str_noticehref[i]=rs_notice.getString(2);
229                     i++;
230                 }
231                 rs_more=stmt.executeQuery("select * from more_news");
232                 i=0;
233                 while(rs_more.next())
234                 {
235                     str_more[i]=rs_more.getString(1);
236                     i++;
237                 }
238             }
239         }
240         catch(Exception e)
241         {
242             e.printStackTrace();
243         }
244     %>
245     <div class="head clearfix" id="head">
246       <div class="title">
247           <p id="example">小趙的學生信息管理系統</p>
248       </div>
249     </div>
250     <div class="wrap" id="wrap">
251         <nav class="nav" id="nav">
252             <ul class="navbar">
253                 <li><a href="mainpage.jsp">首頁</a></li>
254                 <li><a href="usermag.jsp?index=1">普通管理</a></li>
255                 <li><a href="statusmag.jsp?index=1">學籍管理</a></li>
256                 <li><a href="selectclassmag.jsp?index=1">選課管理</a></li>
257                 <li><a href="scoremag.jsp?index=1">成績管理</a></li>
258                 <li><a href="lessonmag.jsp?index=1">課程管理</a></li>
259                 <li><a href="pwdmag.jsp?index=1">密碼管理</a></li>
260             </ul>
261         </nav>
262         <div id="stdtitle" class="stdtitle"></div>
263         <div class="newsshow">
264             <div id="titleimg" class="titleimg"></div>
265             <div id="newstitle" class="newstitle">友情新聞連接</div>
266             <div id="newslist" class="newslist">
267             <h3>學校新聞</h3>
268                 <ul>
269                     <li><a href='<%=str_newshref[0] %>'><%=str_newstitle[0] %></a></li>
270                     <li><a href='<%=str_newshref[1] %>'><%=str_newstitle[1] %></a></li>
271                     <li><a href='<%=str_newshref[2] %>'><%=str_newstitle[2] %></a></li>
272                     <li><a href='<%=str_newshref[3] %>'><%=str_newstitle[3] %></a></li>
273                     <li><a href='<%=str_newshref[4] %>'><%=str_newstitle[4] %></a></li>
274                     <li><a href='<%=str_newshref[5] %>'><%=str_newstitle[5] %></a></li>
275                     <li><a href='<%=str_newshref[6] %>'><%=str_newstitle[6] %></a></li>
276                     <li><a href='<%=str_newshref[7] %>'><%=str_newstitle[7] %></a></li>
277                     <li><a href='<%=str_newshref[8] %>'><%=str_newstitle[8] %></a></li>
278                     <li><a href='<%=str_newshref[9] %>'><%=str_newstitle[9] %></a></li>
279                     <li><a href='<%=str_newshref[10] %>'><%=str_newstitle[10] %></a></li>
280                     <li><a href='<%=str_more[1] %>'>>查看更多</a></li>
281                 </ul>
282                 
283             </div>
284             
285             <div id="noticelist" class="noticelist">
286             <h3>校內公告</h3>
287                 <ul>
288                     <li><a href='<%=str_noticehref[0] %>'><%=str_noticetitle[0] %></a></li>
289                     <li><a href='<%=str_noticehref[1] %>'><%=str_noticetitle[1] %></a></li>
290                     <li><a href='<%=str_noticehref[2] %>'><%=str_noticetitle[2] %></a></li>
291                     <li><a href='<%=str_noticehref[3] %>'><%=str_noticetitle[3] %></a></li>
292                     <li><a href='<%=str_noticehref[4] %>'><%=str_noticetitle[4] %></a></li>
293                     <li><a href='<%=str_noticehref[5] %>'><%=str_noticetitle[5] %></a></li>
294                     <li><a href='<%=str_noticehref[6] %>'><%=str_noticetitle[6] %></a></li>
295                     <li><a href='<%=str_noticehref[7] %>'><%=str_noticetitle[7] %></a></li>
296                     <li><a href='<%=str_noticehref[8] %>'><%=str_noticetitle[8] %></a></li>
297                     <li><a href='<%=str_noticehref[9] %>'><%=str_noticetitle[9] %></a></li>
298                     <li><a href='<%=str_noticehref[10] %>'><%=str_noticetitle[10] %></a></li>
299                     <li><a href='<%=str_more[0] %>'>>查看更多</a></li>
300                 </ul>
301             </div>
302         </div>
303         
304     </div>
305     <div class="foot" id="foot">  
306         <div class="power">    
307             Copyright © 2019 All Rights Reserved.   
308             <div class="information">        
309             <span>聯繫郵箱:1927006283@qq.com</span>    
310             </div>
311             <div class="information">        
312             <span>聯繫地址:石家莊鐵道大學</span>    
313             </div>
314             <div class="information">      
315             <span>聯繫電話:15716888392</span>    
316             </div>    
317         </div>    
318     </div>    
319 </body>
320 </html>
View Code

效果:

點擊連接會跳轉到石家莊鐵道大學官網對應的新聞展現頁面

效果以下:

普通訊息管理頁面:

  1 <%@page import="com.stumag.javabean.Status"%>
  2 <%@page import="java.util.ArrayList"%>
  3 <%@page import="com.stumag.javabean.Password"%>
  4 <%@page import="java.util.List"%>
  5 <%@page import="com.stumag.util.DBUtil"%>
  6 <%@ page language="java" contentType="text/html; charset=GB18030"
  7     pageEncoding="GB18030"%>
  8 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  9 <!DOCTYPE html>
 10 <html>
 11 <head>
 12 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
 13 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
 14 <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
 15 <script type="text/javascript" src="jquery.min.js"></script>
 16 <script type="text/javascript" src="jquery.bumpytext.packed.js"></script>
 17 <script type="text/javascript" src="easying.js"></script>
 18 <script type="text/javascript">
 19     //<![CDATA[
 20     $(document).ready(function() {
 21         $('p#example').bumpyText();
 22     });            //]]>
 23     
 24     $(document).ready(function() {
 25     });
 26 </script>
 27 <title>普通管理</title>
 28 <style type="text/css">
 29     *{
 30         margin:0px;
 31         padding:0px;
 32     }
 33     .head {
 34     background-color: #66CCCC;
 35     text-align: center;
 36     position: relative;
 37     height: 100px;
 38     width: 100;
 39     text-shadow: 5px 5px 4px Black;
 40     }
 41     
 42     .wrap{
 43     width:100;
 44     height:764px;
 45     }
 46     
 47     .foot {
 48     width: 100;
 49     height:200px;
 50     background-color:#CC9933;
 51     position: relative;
 52     text-align:center;
 53     }
 54     .title {    
 55     font-family: "宋體";    
 56     color: #FFFFFF;    
 57     position: absolute;    
 58     top: 50%;    
 59     left: 50%;    
 60     transform: translate(-50%, -50%);  /* 使用css3的transform來實現 */    
 61     font-size: 36px;    
 62     height: 40px;    
 63     width: 30%;
 64     } 
 65     .power {    
 66     font-family: "宋體";
 67     color: #FFFFFF;    
 68     position: absolute;    
 69     top: 50%;
 70     left: 50%;    
 71     transform: translate(-50%, -50%);  
 72     height: 60px;
 73     width: 40%;    
 74     align-content:center;
 75     }     
 76     .foot .power .information {    
 77     width: 100%;    
 78     height: 24px;    
 79     position: relative;
 80     }
 81     .foot .power p {
 82     height: 24px;    
 83     width: 100%;
 84     }
 85     .wrap .nav .navbar{
 86     text-align:center;
 87     text-size:10px;
 88     }
 89     .nav { float: left; clear: both; width: 15%; margin: auto; height:764px; background: #eee; }
 90     .nav ul { list-style: none; margin: 0px; padding: 0px; }
 91     .nav li { float: none; width: 100%; }
 92     .nav li a { display: block; width: 100%; padding: 20px; border-left: 5px solid; position: relative; z-index: 2; text-decoration: none; color: #444; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; }
 93     .nav li a:hover { border-bottom: 0px; color: #fff; }
 94     .nav li:first-child a { border-left: 10px solid #3498db; }
 95     .nav li:nth-child(2) a { border-left: 10px solid #ffd071; }
 96     .nav li:nth-child(3) a { border-left: 10px solid #f0776c; }
 97     .nav li:nth-child(4) a { border-left: 10px solid #9370db; }
 98     .nav li:nth-child(5) a { border-left: 10px solid #9acd32; }
 99     .nav li:nth-child(6) a { border-left: 10px solid #888888; }
100     .nav li:last-child a { border-left: 10px solid #1abc9c; }
101     .nav li a:after { content: ""; height: 100%; left: 0; top: 0; width: 0px; position: absolute; transition: all 0.3s ease 0s; -webkit-transition: all 0.3s ease 0s; z-index: -1; }
102     .nav li a:hover:after { width: 100%; }
103     .nav li:first-child a:after { background: #3498db; }
104     .nav li:nth-child(2) a:after { background: #ffd071; }
105     .nav li:nth-child(3) a:after { background: #f0776c; }
106     .nav li:nth-child(4) a:after { background: #9370db; }
107     .nav li:nth-child(5) a:after { background: #9acd32; }
108     .nav li:nth-child(6) a:after { background: #888888; }
109     .nav li:last-child a:after { background: #1abc9c; }
110     
111     .nav li:nth-child(2) a{background: #ffd071;}
112     
113     .clearfix {display: inline-block;}
114     .clearfix {display: block;}
115     #example{margin-top:-40px;}
116     .bumpy-char {
117     line-height: 3.4em;
118     position: relative;
119     }
120     
121     .wrap .show{
122     position:relative;
123     height:764px;
124     width:85%;
125     float:right;
126     background-size:cover;
127     overflow-y :auto;
128     }
129     
130     .wrap .show .teacherinformation{
131     position:relative;
132     margin-top:20px;
133     margin-bottom:20px;
134     margin-left:auto;
135     margin-right:auto;
136     width:100%;
137     text-align:center;
138     }
139     
140     .userpwd tr{
141     text-align:center;
142     }
143     .userpwd tr th
144     {
145         padding-top:10px;
146         padding-bottom:10px;
147         padding-left:30px;
148         padding-right:30px;
149         text-align:center;
150     }
151     .userpwd tr td
152     {
153         padding-top:10px;
154         padding-bottom:10px;
155         padding-left:30px;
156         padding-right:30px;
157     }
158     
159     .wrap .show div .pagenavbox
160     {
161         position:relative;
162     }
163     
164     .pagenav
165     {
166         list-style:none;
167         width:700px;
168         height:50px;
169         float:left;
170     }
171     .pagenav li
172     {
173         float:left;
174         height:50px;
175         width:50px;
176         margin-left:20px;
177         border-radius:8px;
178         background-color:#99FFCC;
179         line-height:50px;
180     }
181     .pagenav li a
182     {
183         text-decoration:none;
184         display:block;
185         height:50px;
186         cursor:pointer;
187     }
188     .pagenav li a:hover{
189         background-color:#99FFFF;
190         color:black;
191         border-radius:8px;
192     }
193     .wrap .show div .pagenavbox .jumptip
194     {
195         float:left;
196         text-align:center;
197         font-size:16px;
198         overflow:hidden;
199         margin-left:20px;
200         padding-top:10px;
201     }
202     .wrap .show div .pagenavbox .jumptip .jumpto
203     {
204         width:50px;
205         height:30px;
206         border-radius:5px;
207         text-align:center;
208         border-style:none;
209     }
210     .wrap .show div .pagenavbox .jumptip .jumpto:hover
211     {
212         background-color:#CCFFFF;
213     }
214     .wrap .show .inquire
215     {
216         margin:10px auto;
217         text-align:center;
218     }
219     
220     .wrap .show .inquire .inquirebtn
221     {
222         border-radius:5px;
223         border-style:none;
224         height:30px;
225         width:66px;
226     }
227     .wrap .show .inquire .inquirebtn:hover
228     {
229         background-color:#CCFFFF;
230     }
231     .wrap .show .addinformation
232     {
233         position:absolute;
234         display:block;
235         top:5px;
236         right:5px;
237         border-radius:50%;
238         width:40px;
239         height:40px;
240         background-repeat:no-repeat;
241         background-size:cover;
242         background-image:url(images/tianjia.png);
243     }
244     .wrap .show .addinformation:hover
245     {
246         background-image:url(images/tianjia_hover.png);
247     }
248     
249 </style>
250 
251 <script type="text/javascript">
252 
253     function GetQueryString(name) { 
254           var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
255           var r = window.location.search.substr(1).match(reg); //獲取url中"?"符後的字符串並正則匹配
256           var context = ""; 
257           if (r != null) 
258              context = r[2]; 
259           reg = null; 
260           r = null; 
261           return context == null || context == "" || context == "undefined" ? "" : context; 
262     }
263 
264     function Onload()
265     {
266         
267         <%
268             int pagenum=Integer.parseInt(request.getParameter("index"));
269             int totalpage= DBUtil.getPagecount(20,"std_information");
270             int perpageCount=20;
271             String table="std_information";
272             List<Status> sttslist=new ArrayList<Status>();
273             sttslist=DBUtil.showsttsResult(pagenum, perpageCount, table);
274         %>
275         var a_list=document.getElementsByName("navnum");
276         var index=<%=pagenum%>;
277         var total=<%=totalpage%>;
278         
279         if(total<=6)
280         {
281             if(total==6)
282             {
283                 a_list[0].innerHTML=total-5;
284                 a_list[1].innerHTML=total-4;
285                 a_list[2].innerHTML=total-3;
286                 a_list[3].innerHTML=total-2;
287                 a_list[4].innerHTML=total-1;
288                 a_list[5].innerHTML=total;
289                 a_list[index-1].style.cssText=
290                     "background-color:#99FFFF;color:black;border-radius:8px;"
291             }
292             else
293             {
294                 var parent=document.getElementById("pagenav");
295                 var child_list=document.getElementsByName("navnum");
296                 for(var i=0;i<6-total;i++)
297                 {
298                     parent.removeChild(child_list[5-i]);
299                 }
300             }
301         }
302         else
303         {
304             a_list[3].innerHTML="...";
305             a_list[3].setAttribute("href","#");
306             if(index<3)
307             {
308                 a_list[index-1].style.cssText=
309                     "background-color:#99FFFF;color:black;border-radius:8px;"
310                 a_list[4].innerHTML=total-1;
311                 a_list[5].innerHTML=total;
312             }
313             else if(index<total-4)
314             {
315                 a_list[0].innerHTML=index-1;
316                 a_list[1].innerHTML=index;
317                 a_list[1].style.cssText=
318                     "background-color:#99FFFF;color:black;border-radius:8px;";
319                 a_list[2].innerHTML=index+1;
320                 a_list[4].innerHTML=total-1;
321                 a_list[5].innerHTML=total;
322             }
323             else
324             {
325                 a_list[0].innerHTML=total-5;
326                 a_list[1].innerHTML=total-4;
327                 a_list[2].innerHTML=total-3;
328                 a_list[3].innerHTML=total-2;
329                 a_list[4].innerHTML=total-1;
330                 a_list[5].innerHTML=total;
331                 a_list[5-(total-index)].style.cssText=
332                     "background-color:#99FFFF;color:black;border-radius:8px;"
333             }
334         }
335     }
336     
337     function jumpclick(event)
338     {
339         index=event.innerHTML;
340         if(index!="...")
341         {
342             event.setAttribute("href","usermag.jsp?index="+index);
343         }
344         else
345         {
346             event.setAttribute("href","");
347         }
348         
349     }
350     
351     function jumpUporDown(event)
352     {
353         var index=parseInt(GetQueryString("index"));
354         if(index==1&&event.id=="last")
355         {
356             alert("當前是第一頁!");
357         }
358         else if(index==<%=totalpage%>&&event.id=="next")
359         {
360             alert("當前頁是最後一頁!");
361         }
362         else if(event.id=="last")
363         {
364             index=index-1;
365             event.setAttribute("href","usermag.jsp?index="+index);
366         }
367         else if(event.id=="next")
368         {
369             index=index+1;
370             event.setAttribute("href","usermag.jsp?index="+index);
371         }
372     }
373     
374     function jumpto()
375     {
376         var a_list=document.getElementsByName("navnum");
377         var obj=document.getElementById("jumpindex");
378         var indexstr=obj.value;
379         var max=<%=totalpage%>;
380         if(indexstr!="")
381         {
382             index=parseInt(indexstr);
383             if(index<=0||index>max)
384             {
385                 alert("您輸入的頁數不存在!");
386                 obj.value="";
387             }
388             else
389             {
390                 window.location.href="http://localhost:8080/學生管理系統/usermag.jsp?index="+index;   
391             }
392         }
393         else
394         {
395             alert("輸入頁數不能爲空!");
396         }
397         
398     }
399     
400     function tohead(event)
401     {
402         index=1;
403         event.setAttribute("href","usermag.jsp?index="+index);
404     }
405     function totrailer(event)
406     {
407         index=<%=totalpage%>;
408         event.setAttribute("href","usermag.jsp?index="+index);
409     }
410     function updatenormal(event,i)
411     {
412         var id=document.getElementById(i).innerText;
413         var username=document.getElementById("un"+i).innerText;
414         var sex=document.getElementById("us"+i).innerText;
415         var class_num=document.getElementById("uc"+i).innerText;
416         var agency=document.getElementById("ua"+i).innerText;
417         var major=document.getElementById("um"+i).innerText;
418         event.setAttribute("href","updatenormal.jsp?id="+id+"&username="+encodeURI(encodeURI(username))+
419                 "&sex="+encodeURI(encodeURI(sex))+"&class_num="+encodeURI(encodeURI(class_num))+
420                 "&agency="+encodeURI(encodeURI(agency))+"&major="+encodeURI(encodeURI(major)));
421     }
422     function deletenormal(event,i)
423     {
424         var r = confirm("肯定刪除該學生的全部信息?\n(包含成績、課程、學籍)");
425         if (r == true)
426         {
427             var id=document.getElementById(i).innerText;
428             var username=document.getElementById("un"+i).innerText;
429             var sex=document.getElementById("us"+i).innerText;
430             var class_num=document.getElementById("uc"+i).innerText;
431             var agency=document.getElementById("ua"+i).innerText;
432             var major=document.getElementById("um"+i).innerText;
433             event.setAttribute("href","informationdelete_resultshow.jsp?id="+id);
434         }
435         else
436             alert("操做取消");
437         
438     }
439     
440     
441     
442 </script>
443 
444 </head>
445 <body onload="Onload()">
446     <div class="head clearfix" id="head">
447       <div class="title">
448           <p id="example">小趙的學生信息管理系統</p>
449       </div>
450     </div>
451     <div class="wrap" id="wrap">
452         <nav class="nav" id="nav">
453             <ul class="navbar">
454                 <li><a href="mainpage.jsp">首頁</a></li>
455                 <li><a href="usermag.jsp?index=1">普通管理</a></li>
456                 <li><a href="statusmag.jsp?index=1">學籍管理</a></li>
457                 <li><a href="selectclassmag.jsp?index=1">選課管理</a></li>
458                 <li><a href="scoremag.jsp?index=1">成績管理</a></li>
459                 <li><a href="lessonmag.jsp?index=1">課程管理</a></li>
460                 <li><a href="pwdmag.jsp?index=1">密碼管理</a></li>
461             </ul>
462         </nav>
463         <div id="show" class="show">
464             <div id="inquire" class="inquire">
465                 <form action="usermag_orderorinquire.jsp?index=1" method="post">
466                 選擇排序方法:
467                 <select name="sortmethod" id="sortmethod">
468                     <option label="按學號排序" selected="selected" value="0"></option> 
469                     <option label="按姓名排序" value="1"></option> 
470                     <option label="按性別排序" value="2"></option> 
471                     <option label="按班級排序" value="3"></option> 
472                     <option label="按學院排序" value="4"></option> 
473                     <option label="按專業排序" value="5"></option> 
474                 </select>
475                 排序類型:
476                 <select name="sortstyle" id="sortstyle">
477                     <option label="升序" selected="selected" value="0"></option>
478                     <option label="降序" value="1"></option>
479                 </select>
480                 查詢類型:
481                 <select name="inquiretype" id="inquiretype">
482                     <option label="按學號查詢" selected="selected" value="0"></option>
483                     <option label="按姓名查詢" value="1"></option>
484                     <option label="按性別查詢" value="2"></option>
485                     <option label="按班級查詢" value="3"></option>
486                     <option label="按學院查詢" value="4"></option>
487                     <option label="按專業查詢" value="5"></option>
488                 </select>
489                 請輸入查詢內容:
490                 <input type="text" class="inputcontent" name="inputcontent">
491                 <input type="submit" id="inquirebtn" class="inquirebtn" value="執行">
492                 </form>
493             </div>
494             <a href="addinformation.jsp" class="addinformation" title="點此添加學生信息"></a>
495             <div>
496                 <table id="userpwd" class="userpwd table table-hover table-striped table-bordered table-sm">
497                     <tr>
498                         <th>學號</th>
499                         <th>姓名</th>
500                         <th>性別</th>
501                         <th>班級</th>
502                         <th>學院</th>
503                         <th>專業</th>
504                         <th>修改</th>
505                         <th>刪除</th>
506                     </tr>
507                     <c:forEach var="user" items="<%=sttslist %>" varStatus="i">
508                         <tr>
509                             <td id="${i.index+1}">${user.getId()}</td>
510                             <td id="un${i.index+1}">${user.getUsername()}</td>
511                             <td id="us${i.index+1}">${user.getSex()}</td>
512                             <td id="uc${i.index+1}">${user.getClass_num()}</td>
513                             <td id="ua${i.index+1}">${user.getAgency()}</td>
514                             <td id="um${i.index+1}">${user.getMajor()}</td>
515                             <td><a href="#" onclick="updatenormal(this,${i.count})">修改</a></td>
516                             <td><a href="#" onclick="deletenormal(this,${i.count})">刪除</a></td>
517                         </tr>
518                     </c:forEach>
519                 </table>
520                 <div style="text-align:center" class="pagenavbox">
521                     <ul id="pagenav" class="pagenav">
522                         <li><a href="" onclick="tohead(this)">首頁</a></li>
523                         <li><a href="" onclick="jumpUporDown(this)" id="last">上一頁</a></li>
524                         <li><a href="" onclick="jumpclick(this)" name="navnum">1</a></li>
525                         <li><a href="" onclick="jumpclick(this)" name="navnum">2</a></li>
526                         <li><a href="" onclick="jumpclick(this)" name="navnum">3</a></li>
527                         <li><a href="" onclick="jumpclick(this)" name="navnum">4</a></li>
528                         <li><a href="" onclick="jumpclick(this)" name="navnum">5</a></li>
529                         <li><a href="" onclick="jumpclick(this)" name="navnum">6</a></li>
530                         <li><a href="" onclick="jumpUporDown(this)" id="next">下一頁</a></li>
531                         <li><a href="" onclick="totrailer(this)">尾頁</a></li>
532                     </ul>
533                     <div class="jumptip">
534                         當前是第<%=pagenum %>頁;
535                         共有<%=totalpage %>頁,跳轉到
536                         <input type="text" size="4" id="jumpindex" name="jumpindex">537                         <input type="button" value="跳轉" onclick="jumpto()" class="jumpto">
538                     </div>
539                 </div>
540             </div>
541         </div>
542     </div>
543     <div class="footer" id="foot">
544         <div class="power">
545             Copyright © 2019 All Rights Reserved. 
546             <div class="information">
547             <span>聯繫郵箱:1927006283@qq.com</span>
548             </div>
549             <div class="information">
550             <span>聯繫地址:石家莊鐵道大學</span>    
551             </div>
552             <div class="information">
553             <span>聯繫電話:15716888392</span>    
554             </div>    
555         </div>    
556     </div>
557     
558 </body>
559 </html>
View Code

普通訊息管理支持查詢排序的頁面:

  1 <%@page import="com.stumag.javabean.Status"%>
  2 <%@page import="java.util.ArrayList"%>
  3 <%@page import="com.stumag.javabean.Password"%>
  4 <%@page import="java.util.List"%>
  5 <%@page import="com.stumag.util.DBUtil"%>
  6 <%@ page language="java" contentType="text/html; charset=GB18030"
  7     pageEncoding="GB18030"%>
  8 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  9 <!DOCTYPE html>
 10 <html>
 11 <head>
 12 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
 13 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
 14 <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
 15 <script type="text/javascript" src="jquery.min.js"></script>
 16 <script type="text/javascript" src="jquery.bumpytext.packed.js"></script>
 17 <script type="text/javascript" src="easying.js"></script>
 18 <script type="text/javascript">
 19     //<![CDATA[
 20     $(document).ready(function() {
 21         $('p#example').bumpyText();
 22     });            //]]>
 23     
 24     $(document).ready(function() {
 25     });
 26 </script>
 27 <title>普通管理</title>
 28 <style type="text/css">
 29     *{
 30         margin:0px;
 31         padding:0px;
 32     }
 33     .head {
 34     background-color: #66CCCC;
 35     text-align: center;
 36     position: relative;
 37     height: 100px;
 38     width: 100;
 39     text-shadow: 5px 5px 4px Black;
 40     }
 41     
 42     .wrap{
 43     width:100;
 44     height:764px;
 45     }
 46     
 47     .foot {
 48     width: 100;
 49     height:200px;
 50     background-color:#CC9933;
 51     position: relative;
 52     text-align:center;
 53     }
 54     .title {    
 55     font-family: "宋體";    
 56     color: #FFFFFF;    
 57     position: absolute;    
 58     top: 50%;    
 59     left: 50%;    
 60     transform: translate(-50%, -50%);  /* 使用css3的transform來實現 */    
 61     font-size: 36px;    
 62     height: 40px;    
 63     width: 30%;
 64     } 
 65     .power {    
 66     font-family: "宋體";
 67     color: #FFFFFF;    
 68     position: absolute;    
 69     top: 50%;
 70     left: 50%;    
 71     transform: translate(-50%, -50%);  
 72     height: 60px;
 73     width: 40%;    
 74     align-content:center;
 75     }     
 76     .foot .power .information {    
 77     width: 100%;    
 78     height: 24px;    
 79     position: relative;
 80     }
 81     .foot .power p {
 82     height: 24px;    
 83     width: 100%;
 84     }
 85     .wrap .nav .navbar{
 86     text-align:center;
 87     text-size:10px;
 88     }
 89     .nav { float: left; clear: both; width: 15%; margin: auto; height:764px; background: #eee; }
 90     .nav ul { list-style: none; margin: 0px; padding: 0px; }
 91     .nav li { float: none; width: 100%; }
 92     .nav li a { display: block; width: 100%; padding: 20px; border-left: 5px solid; position: relative; z-index: 2; text-decoration: none; color: #444; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; }
 93     .nav li a:hover { border-bottom: 0px; color: #fff; }
 94     .nav li:first-child a { border-left: 10px solid #3498db; }
 95     .nav li:nth-child(2) a { border-left: 10px solid #ffd071; }
 96     .nav li:nth-child(3) a { border-left: 10px solid #f0776c; }
 97     .nav li:nth-child(4) a { border-left: 10px solid #9370db; }
 98     .nav li:nth-child(5) a { border-left: 10px solid #9acd32; }
 99     .nav li:nth-child(6) a { border-left: 10px solid #888888; }
100     .nav li:last-child a { border-left: 10px solid #1abc9c; }
101     .nav li a:after { content: ""; height: 100%; left: 0; top: 0; width: 0px; position: absolute; transition: all 0.3s ease 0s; -webkit-transition: all 0.3s ease 0s; z-index: -1; }
102     .nav li a:hover:after { width: 100%; }
103     .nav li:first-child a:after { background: #3498db; }
104     .nav li:nth-child(2) a:after { background: #ffd071; }
105     .nav li:nth-child(3) a:after { background: #f0776c; }
106     .nav li:nth-child(4) a:after { background: #9370db; }
107     .nav li:nth-child(5) a:after { background: #9acd32; }
108     .nav li:nth-child(6) a:after { background: #888888; }
109     .nav li:last-child a:after { background: #1abc9c; }
110     
111     .nav li:nth-child(2) a{background: #ffd071;}
112     
113     .clearfix {display: inline-block;}
114     .clearfix {display: block;}
115     #example{margin-top:-40px;}
116     .bumpy-char {
117     line-height: 3.4em;
118     position: relative;
119     }
120     
121     .wrap .show{
122     position:relative;
123     height:764px;
124     width:85%;
125     float:right;
126     background-size:cover;
127     overflow-y :auto;
128     }
129     
130     .wrap .show .teacherinformation{
131     position:relative;
132     margin-top:20px;
133     margin-bottom:20px;
134     margin-left:auto;
135     margin-right:auto;
136     width:100%;
137     text-align:center;
138     }
139     
140     .userpwd tr{
141     text-align:center;
142     }
143     .userpwd tr th
144     {
145         padding-top:10px;
146         padding-bottom:10px;
147         padding-left:30px;
148         padding-right:30px;
149         text-align:center;
150     }
151     .userpwd tr td
152     {
153         padding-top:10px;
154         padding-bottom:10px;
155         padding-left:30px;
156         padding-right:30px;
157     }
158     
159     .wrap .show div .pagenavbox
160     {
161         position:relative;
162     }
163     
164     .pagenav
165     {
166         list-style:none;
167         width:700px;
168         height:50px;
169         float:left;
170     }
171     .pagenav li
172     {
173         float:left;
174         height:50px;
175         width:50px;
176         margin-left:20px;
177         border-radius:8px;
178         background-color:#99FFCC;
179         line-height:50px;
180     }
181     .pagenav li a
182     {
183         text-decoration:none;
184         display:block;
185         height:50px;
186         cursor:pointer;
187     }
188     .pagenav li a:hover{
189         background-color:#99FFFF;
190         color:black;
191         border-radius:8px;
192     }
193     .wrap .show div .pagenavbox .jumptip
194     {
195         float:left;
196         text-align:center;
197         font-size:16px;
198         overflow:hidden;
199         margin-left:20px;
200         padding-top:10px;
201     }
202     .wrap .show div .pagenavbox .jumptip .jumpto
203     {
204         width:50px;
205         height:30px;
206         border-radius:5px;
207         text-align:center;
208         border-style:none;
209     }
210     .wrap .show div .pagenavbox .jumptip .jumpto:hover
211     {
212         background-color:#CCFFFF;
213     }
214     .wrap .show .inquire
215     {
216         margin:10px auto;
217         text-align:center;
218     }
219     
220     .wrap .show .inquire .inquirebtn
221     {
222         border-radius:5px;
223         border-style:none;
224         height:30px;
225         width:66px;
226     }
227     .wrap .show .inquire .inquirebtn:hover
228     {
229         background-color:#CCFFFF;
230     }
231     .wrap .show .addinformation
232     {
233         position:absolute;
234         display:block;
235         top:5px;
236         right:5px;
237         border-radius:50%;
238         width:40px;
239         height:40px;
240         background-repeat:no-repeat;
241         background-size:cover;
242         background-image:url(tianjia.png);
243     }
244     .wrap .show .addinformation:hover
245     {
246         background-image:url(tianjia_hover.png);
247     }
248     
249 </style>
250 
251 <script type="text/javascript">
252 
253     function GetQueryString(name) { 
254           var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
255           var r = window.location.search.substr(1).match(reg); //獲取url中"?"符後的字符串並正則匹配
256           var context = ""; 
257           if (r != null) 
258              context = r[2]; 
259           reg = null; 
260           r = null; 
261           return context == null || context == "" || context == "undefined" ? "" : context; 
262     }
263 
264     function Onload()
265     {
266         
267         <%
268             request.setCharacterEncoding("GB18030");
269             String sortmethod=request.getParameter("sortmethod");
270             String sortstyle=request.getParameter("sortstyle");
271             String inquiretype=request.getParameter("inquiretype");
272             String inputcontent=request.getParameter("inputcontent");
273             if(inputcontent==null)
274             {
275                 inputcontent="";
276             }
277             else
278                 inputcontent=java.net.URLDecoder.decode(request.getParameter("inputcontent"), "utf-8");
279             String orderby,where;
280             
281             if(inputcontent!=null&&inputcontent.length()!=0)
282             {
283                 if(inquiretype.equals("0"))
284                     where="where id=\'"+inputcontent+"\' ";
285                 else if(inquiretype.equals("1"))
286                     where="where name=\'"+inputcontent+"\' ";
287                 else if(inquiretype.equals("2"))
288                     where="where sex=\'"+inputcontent+"\' ";
289                 else if(inquiretype.equals("3"))
290                     where="where class=\'"+inputcontent+"\' ";
291                 else if(inquiretype.equals("4"))
292                     where="where agency=\'"+inputcontent+"\' ";
293                 else
294                     where="where major=\'"+inputcontent+"\' ";
295             }
296             else
297             {
298                 where="";
299                 inputcontent="";
300             }
301             System.out.println(where);
302             if(sortmethod.equals("0"))
303                 orderby="order by id ";
304             else if(sortmethod.equals("1"))
305                 orderby="order by name ";
306             else if(sortmethod.equals("2"))
307                 orderby="order by sex ";
308             else if(sortmethod.equals("3"))
309                 orderby="order by class ";
310             else if(sortmethod.equals("4"))
311                 orderby="order by agency ";
312             else
313                 orderby="order by major ";
314             if(sortstyle.equals("1"))
315                 orderby=orderby+"desc ";
316         
317         
318             int pagenum=Integer.parseInt(request.getParameter("index"));
319             int perpageCount=20;
320             String table="std_information ";
321             int totalpage= DBUtil.getTotalPage(pagenum, perpageCount, table, orderby, where);
322             List<Status> sttslist=new ArrayList<Status>();
323             sttslist=DBUtil.showstts_oiResult(pagenum, perpageCount, table, orderby, where);
324         %>
325         var a_list=document.getElementsByName("navnum");
326         var index=<%=pagenum%>;
327         var total=<%=totalpage%>;
328         
329         var sortmethod=<%=sortmethod%>;
330         var sortstyle=<%=sortstyle%>;
331         var inquiretype=<%=inquiretype%>;
332         
333         $("#sortmethod").val(sortmethod);
334         $("#sortstyle").val(sortstyle);
335         $("#inquiretype").val(inquiretype);
336         
337         var inputcontent=document.getElementById("inputcontent");
338         inputcontent.value="<%=inputcontent%>"
339         
340         if(total<=6)
341         {
342             if(total==6)
343             {
344                 a_list[0].innerHTML=total-5;
345                 a_list[1].innerHTML=total-4;
346                 a_list[2].innerHTML=total-3;
347                 a_list[3].innerHTML=total-2;
348                 a_list[4].innerHTML=total-1;
349                 a_list[5].innerHTML=total;
350                 a_list[index-1].style.cssText=
351                     "background-color:#99FFFF;color:black;border-radius:8px;"
352             }
353             else
354             {
355                 for(i=0;i<total;i++)
356                 {
357                     a_list[i].innerHTML=i+1;
358                 }
359                 for(;i<6;i++)
360                 {
361                     a_list[i].innerHTML="×";
362                     a_list[i].style.cssText="background-color:#A0A0A0;color:black;border-radius:8px;font-size:20px";
363                     a_list[i].setAttribute("href","#");
364                 }
365             }
366         }
367         else
368         {
369             a_list[3].innerHTML="...";
370             a_list[3].setAttribute("href","#");
371             if(index<3)
372             {
373                 a_list[index-1].style.cssText=
374                     "background-color:#99FFFF;color:black;border-radius:8px;"
375                 a_list[4].innerHTML=total-1;
376                 a_list[5].innerHTML=total;
377             }
378             else if(index<total-4)
379             {
380                 a_list[0].innerHTML=index-1;
381                 a_list[1].innerHTML=index;
382                 a_list[1].style.cssText=
383                     "background-color:#99FFFF;color:black;border-radius:8px;";
384                 a_list[2].innerHTML=index+1;
385                 a_list[4].innerHTML=total-1;
386                 a_list[5].innerHTML=total;
387             }
388             else
389             {
390                 a_list[0].innerHTML=total-5;
391                 a_list[1].innerHTML=total-4;
392                 a_list[2].innerHTML=total-3;
393                 a_list[3].innerHTML=total-2;
394                 a_list[4].innerHTML=total-1;
395                 a_list[5].innerHTML=total;
396                 a_list[5-(total-index)].style.cssText=
397                     "background-color:#99FFFF;color:black;border-radius:8px;"
398             }
399         }
400     }
401     
402     function jumpclick(event)
403     {
404         var sortmethod=document.getElementById("sortmethod").value;
405         var sortstyle=document.getElementById("sortstyle").value;
406         var inquiretype=document.getElementById("inquiretype").value;
407         var inputcontent=document.getElementById("inputcontent").value;
408         
409         index=event.innerHTML;
410         if(index!="..."||index!="×")
411         {
412             if(inputcontent.length==0)
413             {
414                 event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
415                         sortstyle+"&inquiretype="+inquiretype);
416             }
417             else
418                 event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
419                         sortstyle+"&inquiretype="+inquiretype+"&inputcontent="+encodeURI(encodeURI(inputcontent)));
420             
421         }
422         else
423         {
424             event.setAttribute("href","javascript:return false;");
425         }
426         
427     }
428     
429     function jumpUporDown(event)
430     {
431         var sortmethod=document.getElementById("sortmethod").value;
432         var sortstyle=document.getElementById("sortstyle").value;
433         var inquiretype=document.getElementById("inquiretype").value;
434         var inputcontent=document.getElementById("inputcontent").value;
435         var index=parseInt(GetQueryString("index"));
436         if(index==1&&event.id=="last")
437         {
438             alert("當前是第一頁!");
439             event.setAttribute("href","javascript:return false;");
440         }
441         else if(index==<%=totalpage%>&&event.id=="next")
442         {
443             alert("當前頁是最後一頁!");
444             event.setAttribute("href","javascript:return false;");
445         }
446         else if(event.id=="last")
447         {
448             index=index-1;
449             if(inputcontent.length==0)
450             {
451                 event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
452                         sortstyle+"&inquiretype="+inquiretype);
453             }
454             else
455                 event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
456                         sortstyle+"&inquiretype="+inquiretype+"&inputcontent="+encodeURI(encodeURI(inputcontent)));
457         }
458         else if(event.id=="next")
459         {
460             index=index+1;
461             if(inputcontent.length==0)
462             {
463                 event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
464                         sortstyle+"&inquiretype="+inquiretype);
465             }
466             else
467                 event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
468                         sortstyle+"&inquiretype="+inquiretype+"&inputcontent="+encodeURI(encodeURI(inputcontent)));
469         }
470     }
471     
472     function jumpto()
473     {
474         var sortmethod=document.getElementById("sortmethod").value;
475         var sortstyle=document.getElementById("sortstyle").value;
476         var inquiretype=document.getElementById("inquiretype").value;
477         var inputcontent=document.getElementById("inputcontent").value;
478         var a_list=document.getElementsByName("navnum");
479         var obj=document.getElementById("jumpindex");
480         var indexstr=obj.value;
481         var max=<%=totalpage%>;
482         if(indexstr!="")
483         {
484             index=parseInt(indexstr);
485             if(index<=0||index>max)
486             {
487                 alert("您輸入的頁數不存在!");
488                 obj.value="";
489             }
490             else
491             {
492                 if(inputcontent.length==0)
493                 {
494                     window.location.href="http://localhost:8080/學生管理系統/pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+
495                             sortmethod+"&sortstyle="+sortstyle+"&inquiretype="+inquiretype;
496                 }
497                 else
498                     window.location.href="http://localhost:8080/學生管理系統/pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+
499                     sortmethod+"&sortstyle="+sortstyle+"&inquiretype="+inquiretype+"&inputcontent="+encodeURI(encodeURI(inputcontent));
500             }
501         }
502         else
503         {
504             alert("輸入頁數不能爲空!");
505         }
506         
507     }
508     
509     function tohead(event)
510     {
511         var sortmethod=document.getElementById("sortmethod").value;
512         var sortstyle=document.getElementById("sortstyle").value;
513         var inquiretype=document.getElementById("inquiretype").value;
514         var inputcontent=document.getElementById("inputcontent").value;
515         index=1;
516         if(inputcontent.length==0)
517         {
518             event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
519                     sortstyle+"&inquiretype="+inquiretype);
520         }
521         else
522             event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
523                     sortstyle+"&inquiretype="+inquiretype+"&inputcontent="+encodeURI(encodeURI(inputcontent)));
524     }
525     function totrailer(event)
526     {
527         var sortmethod=document.getElementById("sortmethod").value;
528         var sortstyle=document.getElementById("sortstyle").value;
529         var inquiretype=document.getElementById("inquiretype").value;
530         var inputcontent=document.getElementById("inputcontent").value;
531         index=<%=totalpage%>;
532         if(inputcontent.length==0)
533         {
534             event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
535                     sortstyle+"&inquiretype="+inquiretype);
536         }
537         else
538             event.setAttribute("href","pwdmag_orderorinquire.jsp?index="+index+"&sortmethod="+sortmethod+"&sortstyle="+
539                     sortstyle+"&inquiretype="+inquiretype+"&inputcontent="+encodeURI(encodeURI(inputcontent)));
540     }
541     function updatenormal(event,i)
542     {
543         var id=document.getElementById(i).innerText;
544         var username=document.getElementById("un"+i).innerText;
545         var sex=document.getElementById("us"+i).innerText;
546         var class_num=document.getElementById("uc"+i).innerText;
547         var agency=document.getElementById("ua"+i).innerText;
548         var major=document.getElementById("um"+i).innerText;
549         event.setAttribute("href","updatenormal.jsp?id="+id+"&username="+encodeURI(encodeURI(username))+
550                 "&sex="+encodeURI(encodeURI(sex))+"&class_num="+encodeURI(encodeURI(class_num))+
551                 "&agency="+encodeURI(encodeURI(agency))+"&major="+encodeURI(encodeURI(major)));
552     }
553     function deletenormal(event,i)
554     {
555         var r = confirm("肯定刪除該學生的全部信息?\n(包含成績、課程、學籍)");
556         if (r == true)
557         {
558             var id=document.getElementById(i).innerText;
559             var username=document.getElementById("un"+i).innerText;
560             var sex=document.getElementById("us"+i).innerText;
561             var class_num=document.getElementById("uc"+i).innerText;
562             var agency=document.getElementById("ua"+i).innerText;
563             var major=document.getElementById("um"+i).innerText;
564             event.setAttribute("href","informationdelete_resultshow.jsp?id="+id);
565         }
566         else
567             alert("操做取消");
568         
569     }
570     
571 </script>
572 
573 </head>
574 <body onload="Onload()">
575     <div class="head clearfix" id="head">
576       <div class="title">
577           <p id="example">小趙的學生信息管理系統</p>
578       </div>
579     </div>
580     <div class="wrap" id="wrap">
581         <nav class="nav" id="nav">
582             <ul class="navbar">
583                 <li><a href="mainpage.jsp">首頁</a></li>
584                 <li><a href="usermag.jsp?index=1">普通管理</a></li>
585                 <li><a href="statusmag.jsp?index=1">學籍管理</a></li>
586                 <li><a href="selectclassmag.jsp?index=1">選課管理</a></li>
587                 <li><a href="scoremag.jsp?index=1">成績管理</a></li>
588                 <li><a href="lessonmag.jsp?index=1">課程管理</a></li>
589                 <li><a href="pwdmag.jsp?index=1">密碼管理</a></li>
590             </ul>
591         </nav>
592         <div id="show" class="show">
593             <div id="inquire" class="inquire">
594                 <form action="usermag_orderorinquire.jsp?index=1" method="post">
595                 選擇排序方法:
596                 <select name="sortmethod" id="sortmethod">
597                     <option label="按學號排序" selected="selected" value="0"></option> 
598                     <option label="按姓名排序" value="1"></option> 
599                     <option label="按性別排序" value="2"></option> 
600                     <option label="按班級排序" value="3"></option> 
601                     <option label="按學院排序" value="4"></option> 
602                     <option label="按專業排序" value="5"></option> 
603                 </select>
604                 排序類型:
605                 <select name="sortstyle" id="sortstyle">
606                     <option label="升序" selected="selected" value="0"></option>
607                     <option label="降序" value="1"></option>
608                 </select>
609                 查詢類型:
610                 <select name="inquiretype" id="inquiretype">
611                     <option label="按學號查詢" selected="selected" value="0"></option>
612                     <option label="按姓名查詢" value="1"></option>
613                     <option label="按性別查詢" value="2"></option>
614                     <option label="按班級查詢" value="3"></option>
615                     <option label="按學院查詢" value="4"></option>
616                     <option label="按專業查詢" value="5"></option>
617                 </select>
618                 請輸入查詢內容:
619                 <input type="text" class="inputcontent" name="inputcontent" id="inputcontent">
620                 <input type="submit" id="inquirebtn" class="inquirebtn" value="執行">
621                 </form>
622             </div>
623             <a href="addinformation.jsp" class="addinformation" title="點此添加學生信息"></a>
624             <div>
625                 <table id="userpwd" class="userpwd table table-hover table-striped table-bordered table-sm">
626                     <tr>
627                         <th>學號</th>
628                         <th>姓名</th>
629                         <th>性別</th>
630                         <th>班級</th>
631                         <th>學院</th>
632                         <th>專業</th>
633                         <th>修改</th>
634                         <th>刪除</th>
635                     </tr>
636                     <c:forEach var="user" items="<%=sttslist %>" varStatus="i">
637                         <tr>
638                             <td id="${i.index+1}">${user.getId()}</td>
639                             <td id="un${i.index+1}">${user.getUsername()}</td>
640                             <td id="us${i.index+1}">${user.getSex()}</td>
641                             <td id="uc${i.index+1}">${user.getClass_num()}</td>
642                             <td id="ua${i.index+1}">${user.getAgency()}</td>
643                             <td id="um${i.index+1}">${user.getMajor()}</td>
644                             <td><a href="#" onclick="updatenormal(this,${i.count})">修改</a></td>
645                             <td><a href="#" onclick="deletenormal(this,${i.count})">刪除</a></td>
646                         </tr>
647                     </c:forEach>
648                 </table>
649                 <div style="text-align:center" class="pagenavbox">
650                     <ul id="pagenav" class="pagenav">
651                         <li><a href="" onclick="tohead(this)">首頁</a></li>
652                         <li><a href="" onclick="jumpUporDown(this)" id="last">上一頁</a></li>
653                         <li><a href="" onclick="jumpclick(this)" name="navnum">1</a></li>
654                         <li><a href="" onclick="jumpclick(this)" name="navnum">2</a></li>
655                         <li><a href="" onclick="jumpclick(this)" name="navnum">3</a></li>
656                         <li><a href="" onclick="jumpclick(this)" name="navnum">4</a></li>
657                         <li><a href="" onclick="jumpclick(this)" name="navnum">5</a></li>
658                         <li><a href="" onclick="jumpclick(this)" name="navnum">6</a></li>
659                         <li><a href="" onclick="jumpUporDown(this)" id="next">下一頁</a></li>
660                         <li><a href="" onclick="totrailer(this)">尾頁</a></li>
661                     </ul>
662                     <div class="jumptip">
663                         當前是第<%=pagenum %>頁;
664                         共有<%=totalpage %>頁,跳轉到
665                         <input type="text" size="4" id="jumpindex" name="jumpindex">666                         <input type="button" value="跳轉" onclick="jumpto()" class="jumpto">
667                     </div>
668                 </div>
669             </div>
670         </div>
671     </div>
672     <div class="foot" id="foot">
673         <div class="power">
674             Copyright © 2019 All Rights Reserved. 
675             <div class="information">
676             <span>聯繫郵箱:1927006283@qq.com</span>
677             </div>
678             <div class="information">
679             <span>聯繫地址:石家莊鐵道大學</span>    
680             </div>
681             <div class="information">
682             <span>聯繫電話:15716888392</span>    
683             </div>    
684         </div>    
685     </div>
686     
687 </body>
688 </html>
View Code

效果:

默認是按照學院名排序,下面是分頁插件

支持翻頁動態刷新頁碼及跳轉功能:

修改基本信息頁面:

  1 <%@page import="com.stumag.javabean.Status"%>
  2 <%@page import="java.util.ArrayList"%>
  3 <%@page import="com.stumag.javabean.Password"%>
  4 <%@page import="java.util.List"%>
  5 <%@page import="java.sql.ResultSet"%>
  6 <%@page import="java.sql.PreparedStatement"%>
  7 <%@page import="java.sql.Connection"%>
  8 <%@page import="com.stumag.util.DBUtil"%>
  9 <%@ page language="java" contentType="text/html; charset=GB18030"
 10     pageEncoding="GB18030"%>
 11 <!DOCTYPE html>
 12 <html>
 13 <head>
 14 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
 15 <title>基本信息修改</title>
 16 <style>
 17     *{
 18     margin=0;
 19     padding=0;
 20     }
 21     .head{
 22     width:100;
 23     height:100px;
 24     text-align:center;
 25     background-color:#66CCCC;
 26     position:relative;
 27     text-shadow: 5px 5px 4px Black;
 28     }
 29     .wrap{
 30     width:100;
 31     height:768px;
 32     background-image:url(images/earth.jpg);
 33     background-size:cover;
 34     background-repeat:no-repeat;
 35     background-position:center center;
 36     position:relative;
 37     }
 38     .foot {
 39     width: 100;
 40     height:200px;
 41     background-color:black;
 42     position: relative;
 43     }
 44     .title {    
 45     font-family: "宋體";    
 46     color: #FFFFFF;    
 47     position: absolute;    
 48     transform: translate(-50%, -50%);
 49     font-size: 36px;    
 50     height: 40px;    
 51     width: 30%;
 52     top: 50%;    
 53     left: 50%;    
 54     } 
 55     .power {    
 56     font-family: "宋體";
 57     color: #FFFFFF;    
 58     position: absolute;    
 59     top: 50%;    
 60     left: 50%;    
 61     transform: translate(-50%, -50%);  
 62     height: 60px;    
 63     width: 40%;    
 64     text-align:center;
 65     }     
 66     .foot .power p {    
 67     height: 24px;    
 68     width: 100%;
 69     }
 70     .foot .power .information {    
 71     width: 100%;    
 72     height: 24px;    
 73     position: relative;
 74     }
 75     .container{
 76     width: 400px;
 77     height: 100;
 78     padding: 13px;
 79     position: absolute;
 80     left: 50%;
 81     top: 40%;
 82     margin-left: -200px;    
 83     margin-top: -200px;     
 84     background-color: rgba(240, 255, 255, 0.5);     
 85     border-radius: 10px;
 86     text-align: center;
 87     }
 88     .input_hint{
 89     width:30%;
 90     height:20px;
 91     position:relative;
 92     margin-top:10px;
 93     margin-bottom:0px;
 94     margin-left:0px;
 95     margin-right:auto;
 96     font-size:20sp;
 97     }
 98     .wrap .container .signintext{    
 99     width: 86%;    
100     border-bottom: 1px solid #ee7700;
101     margin-bottom: 60px;
102     margin-top: 0px;    
103     margin-right: auto;    
104     margin-left: auto;
105     }
106     .wrap .container .signintext .signinp{
107     display: inline-block;
108     font-size: 28px;
109     width:86%;
110     margin-top: 30px;
111     }
112     .wrap .container .user{
113     position:relative;
114     margin-top:20px;
115     margin-bottom:20px;
116     margin-left:auto;
117     margin-right:auto;
118     }
119     div div table td{
120     padding:10px;
121     text-align:left;
122     }
123     .wrap .container .user .signinput{
124     width:70%;
125     height:35px;
126     }
127     .wrap .container .user .signinput .i_input{
128     height:100%;
129     border-radius:5px;
130     border:none;
131     background-color:rgba(232,232,232,0.5) ;
132     }
133     .wrap .container .signbtn{
134     width:100%;
135     height: 42px;
136     background-color: #ee7700;
137     border: none;
138     color: white;
139     margin-top:20px;
140     margin-bottom:10px;
141     font-size: 18px;
142     border-radius:8px;
143     }
144 </style>
145 
146 </head>
147 <body>
148     <%
149         String userid=request.getParameter("id");
150         //String username=request.getParameter("username");
151         String username = java.net.URLDecoder.decode(request.getParameter("username"), "utf-8");
152         String sex = java.net.URLDecoder.decode(request.getParameter("sex"), "utf-8");
153         String class_num = java.net.URLDecoder.decode(request.getParameter("class_num"), "utf-8");
154         String agency = java.net.URLDecoder.decode(request.getParameter("agency"), "utf-8");
155         String major = java.net.URLDecoder.decode(request.getParameter("major"), "utf-8");
156         Status stts=new Status();
157         stts.setId(userid);
158         stts.setUsername(username);
159         stts.setSex(sex);
160         stts.setClass_num(class_num);
161         stts.setAgency(agency);
162         stts.setMajor(major);
163     %>
164     <script>
165         function Onclick()
166         {
167             var oldid=<%=stts.getId() %>
168             var id=document.getElementById("id").value;
169             var username=document.getElementById("username").value;
170             var sex=document.getElementById("sex").value;
171             var class_num=document.getElementById("class_num").value;
172             var agency=document.getElementById("agency").value;
173             var major=document.getElementById("major").value;
174             if(id==""||username==""||sex==""||class_num==""||agency==""||major=="")
175             {
176                 alert("包含空的信息\n請將空信息填寫完整");
177             }
178             else
179             {
180                 var form=document.getElementById("update");
181                 form.setAttribute("action","updatenormal_do?oldid="+oldid+"&id="+id+"&username="+encodeURI(encodeURI(username))+
182                         "&sex="+encodeURI(encodeURI(sex))+"&class_num="+encodeURI(encodeURI(class_num))+
183                         "&agency="+encodeURI(encodeURI(agency))+"&major="+encodeURI(encodeURI(major)));
184             }
185         }
186     </script>
187     <div id="header" class="head">
188         <div class="title">小趙的學生信息管理系統</div>
189     </div>
190     <div class="wrap" id="wrap">
191         <div id="container" class="container">
192             <div class="signintext">
193                 <p class="signinp">修改基本信息</p>
194             </div>
195             <form action="" method="post" id="update">
196                 <table class="user">
197                     <tr>
198                     <td class="input_hint"><label>學號:</label></td>
199                     <td class="signinput"><input class="i_input" name="id" id="id" type="text" value="<%=stts.getId() %>"></td>
200                     </tr>
201 
202                     <tr>
203                     <td class="input_hint"><label>姓名:</label></td>
204                     <td class="signinput"><input class="i_input" name="username" id="username"type="text" value="<%=stts.getUsername() %>"></td>
205                     </tr>
206                     
207                     <tr>
208                     <td class="input_hint"><label>性別:</label></td>
209                     <td class="signinput"><input class="i_input" name="sex" id="sex" type="text" value="<%=stts.getSex() %>"></td>
210                     </tr>
211                     
212                     <tr>
213                     <td class="input_hint"><label>班級:</label></td>
214                     <td class="signinput"><input class="i_input" name="class_num" id="class_num" type="text" value="<%=stts.getClass_num() %>"></td>
215                     </tr>
216                     
217                     <tr>
218                     <td class="input_hint"><label>學院:</label></td>
219                     <td class="signinput"><input class="i_input" name="agency" id="agency" type="text" value="<%=stts.getAgency() %>"></td>
220                     </tr>
221                     
222                     <tr>
223                     <td class="input_hint"><label>專業:</label></td>
224                     <td class="signinput"><input class="i_input" name="major" id="major" type="text" value="<%=stts.getMajor() %>"></td>
225                     </tr>
226                     
227                     <tr>
228                     <td colspan="2"><input class="signbtn" type="submit" value="確認修改" onclick="Onclick()"></td>
229                     </tr>
230                 </table>
231             </form>
232         </div>
233     </div>
234     <div class="foot" id="foot">
235         <div class="power">    
236             Copyright © 2019 All Rights Reserved.   
237             <div class="information">
238             <span>聯繫郵箱:1927006283@qq.com</span>    
239             </div>        
240             <div class="information">        
241             <span>聯繫地址:石家莊鐵道大學</span>    
242             </div>          
243             <div class="information">      
244             <span>聯繫電話:15716888392</span>    
245             </div>    
246         </div>    
247     </div>
248 </body>
249 </html>
View Code

點擊某條信息後跳轉到信息編輯頁面,並提供修改前的默認值。在這裏若是修改學號,數據庫中對應學號位置的信息會被修改後的信息取代(學號做爲primary key)

在這裏以最後一個同窗 姓名 尤化宇爲例,修改其性別爲女

能夠看到信息已經修改

下面是處理修改信息的servlet的源碼:

 1 package com.stumag.servlet;
 2 
 3 import java.io.IOException;
 4 import java.sql.Connection;
 5 import java.sql.PreparedStatement;
 6 
 7 import javax.servlet.ServletException;
 8 import javax.servlet.annotation.WebServlet;
 9 import javax.servlet.http.HttpServlet;
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
12 
13 import com.stumag.util.DBUtil;
14 
15 /**
16  * Servlet implementation class updatenormal_do
17  */
18 @WebServlet("/updatenormal_do")
19 public class updatenormal_do extends HttpServlet {
20     private static final long serialVersionUID = 1L;
21     
22     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
23         // TODO Auto-generated method stub
24         String oldid=request.getParameter("oldid");
25         String id=request.getParameter("id");
26         String username = java.net.URLDecoder.decode(request.getParameter("username"), "utf-8");
27         String sex = java.net.URLDecoder.decode(request.getParameter("sex"), "utf-8");
28         String class_num = java.net.URLDecoder.decode(request.getParameter("class_num"), "utf-8");
29         String agency = java.net.URLDecoder.decode(request.getParameter("agency"), "utf-8");
30         String major = java.net.URLDecoder.decode(request.getParameter("major"), "utf-8");
31         Connection con=null;
32         PreparedStatement pstmt=null;
33         try {
34             con=DBUtil.getConnection();
35             System.out.println(id+username+sex+class_num+agency+major+oldid);
36             String sql_query="update std_information set id=? , name=? , sex=? , class=? , agency=? , major=? where id = ?";
37             String sql_query2="update std_score set id=? , username=? , agency=? , major=? , class=? where id = ?";
38             pstmt=con.prepareStatement(sql_query);
39             pstmt.setString(1, id);
40             pstmt.setString(2, username);
41             pstmt.setString(3, sex);
42             pstmt.setString(4, class_num);
43             pstmt.setString(5, agency);
44             pstmt.setString(6, major);
45             pstmt.setString(7, oldid);
46             pstmt.executeUpdate();
47             pstmt=con.prepareStatement(sql_query2);
48             pstmt.setString(1, id);
49             pstmt.setString(2, username);
50             pstmt.setString(3, agency);
51             pstmt.setString(4, major);
52             pstmt.setString(5, class_num);
53             pstmt.setString(6, oldid);
54             pstmt.executeUpdate();
55             request.getRequestDispatcher("normalupdate_resultshow.jsp?result=1").forward(request, response);
56         }
57         catch (Exception e) {
58             e.printStackTrace();
59             System.out.println("數據庫信息更新失敗"); 
60             request.getRequestDispatcher("normalupdate_resultshow.jsp?result=0").forward(request, response);
61         }
62         
63     }
64 
65 }
View Code

下面是顯示操做結果的jsp源碼:

 1 <%@ page language="java" contentType="text/html; charset=GB18030"
 2     pageEncoding="GB18030"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
 7 <title>操做結果</title>
 8 <style>
 9 *{
10 margin:0px;
11 padding:0px;
12 text-align:center;
13 }
14 </style>
15 <script>
16     function Onload()
17     {
18         var show=document.getElementById("show");
19         if(<%=request.getParameter("result")%>==0)
20         {
21             show.innerText="操做失敗,即將返回主頁……";
22         }
23         else
24         {
25             show.innerText="用戶普通訊息修改爲功,即將返回主頁……";
26         }
27     }
28 </script>
29 </head>
30 <body onload="Onload()">
31 <%   response.setHeader("Refresh", "2;url=usermag.jsp?index=1"); %>
32     <h2 id="show"></h2>
33 </body>
34 </html>
View Code

頁面支持不一樣條件下的查詢及排序方式如根據姓名、性別、學院、專業、班級等。下面其餘有查詢排序功能的頁面與此相同,再也不敘述

頁面右上角的「+」按鈕用來添加學生信息,點擊跳轉:

這裏添加一個姓名爲李四的學生信息

添加信息頁代碼:

  1 <%@page import="com.stumag.javabean.Status"%>
  2 <%@page import="java.util.ArrayList"%>
  3 <%@page import="com.stumag.javabean.Password"%>
  4 <%@page import="java.util.List"%>
  5 <%@page import="java.sql.ResultSet"%>
  6 <%@page import="java.sql.PreparedStatement"%>
  7 <%@page import="java.sql.Connection"%>
  8 <%@page import="com.stumag.util.DBUtil"%>
  9 <%@ page language="java" contentType="text/html; charset=GB18030"
 10     pageEncoding="GB18030"%>
 11 <!DOCTYPE html>
 12 <html>
 13 <head>
 14 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
 15 <title>基本信息修改</title>
 16 <style>
 17     *{
 18     margin=0;
 19     padding=0;
 20     }
 21     .header{
 22     width:100;
 23     height:100px;
 24     text-align:center;
 25     background-color:#66CCCC;
 26     position:relative;
 27     text-shadow: 5px 5px 4px Black;
 28     }
 29     .wrap{
 30     width:100;
 31     height:768px;
 32     background-image:url(images/earth.jpg);
 33     background-size:cover;
 34     background-repeat:no-repeat;
 35     background-position:center center;
 36     position:relative;
 37     overflow-y:auto;
 38     }
 39     .foot {
 40     width: 100;
 41     height:200px;
 42     background-color:black;
 43     position: relative;
 44     }
 45     .title {    
 46     font-family: "宋體";    
 47     color: #FFFFFF;    
 48     position: absolute;    
 49     transform: translate(-50%, -50%);
 50     font-size: 36px;    
 51     height: 40px;    
 52     width: 30%;
 53     top: 50%;    
 54     left: 50%;    
 55     } 
 56     .power {    
 57     font-family: "宋體";
 58     color: #FFFFFF;    
 59     position: absolute;    
 60     top: 50%;    
 61     left: 50%;    
 62     transform: translate(-50%, -50%);  
 63     height: 60px;    
 64     width: 40%;    
 65     text-align:center;
 66     }     
 67     .foot .power p {    
 68     height: 24px;    
 69     width: 100%;
 70     }
 71     .foot .power .information {    
 72     width: 100%;    
 73     height: 24px;    
 74     position: relative;
 75     }
 76     .container{
 77     width: 400px;
 78     height: 100;
 79     padding: 13px;
 80     position: absolute;
 81     left: 50%;
 82     top: 40%;
 83     margin-left: -200px;    
 84     margin-top: -200px;     
 85     background-color: rgba(240, 255, 255, 0.5);     
 86     border-radius: 10px;
 87     text-align: center;
 88     }
 89     .input_hint{
 90     width:30%;
 91     height:20px;
 92     position:relative;
 93     margin-top:10px;
 94     margin-bottom:0px;
 95     margin-left:0px;
 96     margin-right:auto;
 97     font-size:20sp;
 98     }
 99     .wrap .container .signintext{    
100     width: 86%;    
101     border-bottom: 1px solid #ee7700;
102     margin-bottom: 60px;
103     margin-top: 0px;    
104     margin-right: auto;    
105     margin-left: auto;
106     }
107     .wrap .container .signintext .signinp{
108     display: inline-block;
109     font-size: 28px;
110     width:86%;
111     margin-top: 30px;
112     }
113     .wrap .container .user{
114     position:relative;
115     margin-top:20px;
116     margin-bottom:20px;
117     margin-left:auto;
118     margin-right:auto;
119     }
120     div div table td{
121     padding:10px;
122     text-align:left;
123     }
124     .wrap .container .user .signinput{
125     width:70%;
126     height:35px;
127     }
128     .wrap .container .user .signinput .i_input{
129     height:100%;
130     border-radius:5px;
131     border:none;
132     background-color:rgba(232,232,232,0.5) ;
133     }
134     .wrap .container .signbtn{
135     width:100%;
136     height: 42px;
137     background-color: #ee7700;
138     border: none;
139     color: white;
140     margin-top:20px;
141     margin-bottom:10px;
142     font-size: 18px;
143     border-radius:8px;
144     }
145 </style>
146 
147 </head>
148 <body>
149     <script>
150         function Onclick()
151         {
152             var id=document.getElementById("id").value;
153             var username=document.getElementById("username").value;
154             var sex=document.getElementById("sex").value;
155             var class_num=document.getElementById("class_num").value;
156             var agency=document.getElementById("agency").value;
157             var major=document.getElementById("major").value;
158             var email=document.getElementById("email").value;
159             var password=document.getElementById("password").value;
160             if(id==""||username==""||sex==""||class_num==""||agency==""||major==""||email==""||password=="")
161             {
162                 alert("包含空的信息\n請將空信息填寫完整");
163             }
164             else
165             {
166                 var form=document.getElementById("update");
167                 form.setAttribute("action","addinformation_do?id="+id+"&username="+encodeURI(encodeURI(username))+
168                         "&sex="+encodeURI(encodeURI(sex))+"&class_num="+encodeURI(encodeURI(class_num))+
169                         "&agency="+encodeURI(encodeURI(agency))+"&major="+encodeURI(encodeURI(major))+"&email="+email+
170                         "&password="+password);
171             }
172         }
173     </script>
174     <div id="header" class="header">
175         <div class="title">小趙的學生信息管理系統</div>
176     </div>
177     <div class="wrap" id="wrap">
178         <div class="container">
179             <div class="signintext">
180                 <p class="signinp">添加基本信息</p>
181             </div>
182             <form action="" method="post" id="update">
183                 <table class="user">
184                     <tr>
185                     <td class="input_hint"><label>學號:</label></td>
186                     <td class="signinput"><input class="i_input" name="id" id="id" type="text"></td>
187                     </tr>
188 
189                     <tr>
190                     <td class="input_hint"><label>姓名:</label></td>
191                     <td class="signinput"><input class="i_input" name="username" id="username"type="text"></td>
192                     </tr>
193                     
194                     <tr>
195                     <td class="input_hint"><label>性別:</label></td>
196                     <td class="signinput"><input class="i_input" name="sex" id="sex" type="text"></td>
197                     </tr>
198                     
199                     <tr>
200                     <td class="input_hint"><label>班級:</label></td>
201                     <td class="signinput"><input class="i_input" name="class_num" id="class_num" type="text"></td>
202                     </tr>
203                     
204                     <tr>
205                     <td class="input_hint"><label>學院:</label></td>
206                     <td class="signinput"><input class="i_input" name="agency" id="agency" type="text"></td>
207                     </tr>
208                     
209                     <tr>
210                     <td class="input_hint"><label>專業:</label></td>
211                     <td class="signinput"><input class="i_input" name="major" id="major" type="text"></td>
212                     </tr>
213                     
214                     <tr>
215                     <td class="input_hint"><label>郵箱:</label></td>
216                     <td class="signinput"><input class="i_input" name="email" id="email" type="email"></td>
217                     </tr>
218                     
219                     <tr>
220                     <td class="input_hint"><label>密碼:</label></td>
221                     <td class="signinput"><input class="i_input" name="password" id="password" type="text"></td>
222                     </tr>
223                     
224                     <tr>
225                     <td colspan="2"><input class="signbtn" type="submit" value="確認添加" onclick="Onclick()"></td>
226                     </tr>
227                 </table>
228             </form>
229         </div>
230     </div>
231     <div class="foot" id="foot">
232         <div class="power">    
233             Copyright © 2019 All Rights Reserved.   
234             <div class="information">
235             <span>聯繫郵箱:1927006283@qq.com</span>    
236             </div>        
237             <div class="information">        
238             <span>聯繫地址:石家莊鐵道大學</span>    
239             </div>          
240             <div class="information">      
241             <span>聯繫電話:15716888392</span>    
242             </div>    
243         </div>    
244     </div>
245 </body>
246 </html>
View Code

處理信息添加的servlet代碼:

 1 package com.stumag.servlet;
 2 
 3 import java.io.IOException;
 4 import java.sql.Connection;
 5 import java.sql.PreparedStatement;
 6 
 7 import javax.servlet.ServletException;
 8 import javax.servlet.annotation.WebServlet;
 9 import javax.servlet.http.HttpServlet;
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
12 
13 import com.stumag.util.DBUtil;
14 
15 /**
16  * Servlet implementation class addinformation_do
17  */
18 @WebServlet("/addinformation_do")
19 public class addinformation_do extends HttpServlet {
20     private static final long serialVersionUID = 1L;
21     
22     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
23         // TODO Auto-generated method stub
24 //        String id=request.getParameter("id");
25 //        String name=request.getParameter("name");
26 //        String sex=request.getParameter("sex");
27 //        String agency=request.getParameter("agency");
28 //        String major=request.getParameter("major");
29 //        String class_num=request.getParameter("class_num");
30         
31         String id=request.getParameter("id");
32         String name = java.net.URLDecoder.decode(request.getParameter("username"), "utf-8");
33         String sex = java.net.URLDecoder.decode(request.getParameter("sex"), "utf-8");
34         String class_num = request.getParameter("class_num");
35         String agency = java.net.URLDecoder.decode(request.getParameter("agency"), "utf-8");
36         String major = java.net.URLDecoder.decode(request.getParameter("major"), "utf-8");
37         String email=request.getParameter("email");
38         String password=request.getParameter("password");
39         Connection connection=null;
40         PreparedStatement preparedStatement=null;
41         try {
42             connection=DBUtil.getConnection();
43             String sql="insert into std_information(id,name,sex,agency,major,class,email,password) values (?,?,?,?,?,?,?,?)";
44             preparedStatement=connection.prepareStatement(sql);
45             preparedStatement.setString(1, id);
46             preparedStatement.setString(2, name);
47             preparedStatement.setString(3, sex);
48             preparedStatement.setString(4, agency);
49             preparedStatement.setString(5, major);
50             preparedStatement.setString(6, class_num);
51             preparedStatement.setString(7, email);
52             preparedStatement.setString(8, password);
53             preparedStatement.executeUpdate();
54             sql="insert into std_score(id,username,agency,major,class) values(?,?,?,?,?)";
55             preparedStatement=connection.prepareStatement(sql);
56             preparedStatement.setString(1, id);
57             preparedStatement.setString(2, name);
58             preparedStatement.setString(3, agency);
59             preparedStatement.setString(4, major);
60             preparedStatement.setString(5, class_num);
61             preparedStatement.executeUpdate();
62             
63             sql="insert into std_status(id,name,sex,agency,major,class_num) values (?,?,?,?,?,?)";
64             preparedStatement=connection.prepareStatement(sql);
65             preparedStatement.setString(1, id);
66             preparedStatement.setString(2, name);
67             preparedStatement.setString(3, sex);
68             preparedStatement.setString(4, agency);
69             preparedStatement.setString(5, major);
70             preparedStatement.setString(6, class_num);
71             preparedStatement.executeUpdate();
72             
73             request.getRequestDispatcher("addinformation_resultshow.jsp?result=1").forward(request, response);
74             
75         } catch (Exception e) {
76             // TODO: handle exception
77             e.printStackTrace();
78             request.getRequestDispatcher("addinformation_resultshow.jsp?result=0").forward(request, response);
79         }
80     }
81 
82 }
View Code

操做結果顯示頁代碼:

 1 <%@ page language="java" contentType="text/html; charset=GB18030"
 2     pageEncoding="GB18030"%>
 3 <%@ page buffer="16kb" %>  
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
 8 <title>操做結果</title>
 9 <style>
10 *{
11 margin:0px;
12 padding:0px;
13 text-align:center;
14 }
15 </style>
16 <script>
17     function Onload()
18     {
19         var show=document.getElementById("show");
20         if(<%=request.getParameter("result")%>==0)
21         {
22             show.innerText="操做失敗,即將返回主頁……";
23         }
24         else
25         {
26             show.innerText="學生信息添加成功,即將返回主頁……";
27         }
28     }
29 </script>
30 </head>
31 <body onload="Onload()">
32 <%   response.setHeader("Refresh", "2;url=usermag.jsp?index=1"); %>
33     <h2 id="show"></h2>
34 </body>
35 </html>
View Code

回到主頁按姓名查詢李四

 

 

下面以軟件工程專業爲例進行按學號降序排序的查詢:

 

點擊執行後結果以下:

能夠看到查詢軟件工程專業的學生基本信息已經按照學號倒序排列,分頁插件的「×」符號樣式的按鈕表示按鈕不可點擊

下面展現刪除信息的功能,咱們以軟件工程頁最後一名學生吳霸爲例刪除學生信息,首先按姓名查詢到「吳霸」的信息

而後點擊刪除,會彈出提示框

在此刪除學生基本信息以後,數據庫中全部包含該信息的表中的對應條目均會被刪除,在這裏點擊肯定

返回主頁後咱們再次查詢該條信息

發現返回結果頁面條目爲空,全部頁數導航按鈕均爲不可點擊,結果頁總頁數爲0,信息刪除成功

下面是處理刪除信息並展現操做結果的jsp代碼:

 1 <%@page import="com.stumag.util.DBUtil"%>
 2 <%@page import="java.sql.PreparedStatement"%>
 3 <%@page import="java.sql.Connection"%>
 4 <%@ page language="java" contentType="text/html; charset=GB18030"
 5     pageEncoding="GB18030"%>
 6 <%@ page buffer="16kb" %>  
 7 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 8 <html>
 9 <head>
10 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
11 <title>操做結果</title>
12 <style>
13 *{
14 margin:0px;
15 padding:0px;
16 text-align:center;
17 }
18 </style>
19 <script>
20     function Onload()
21     {
22         <%
23             Connection con=null;
24             PreparedStatement pstmt=null;
25             String userid=request.getParameter("id");
26             String sql1="delete from std_information where id="+userid;
27             String sql2="delete from std_score where id="+userid;
28             String sql3="delete from std_status where id="+userid;
29             int result;
30             try {
31                 con=DBUtil.getConnection();
32                 pstmt=con.prepareStatement(sql1);
33                 pstmt.executeUpdate();
34                 pstmt=con.prepareStatement(sql2);
35                 pstmt.executeUpdate();
36                 pstmt=con.prepareStatement(sql3);
37                 pstmt.executeUpdate();
38                 result=1;
39             }
40             catch (Exception e) {
41                 System.out.println("數據庫信息更新失敗");
42                 e.printStackTrace();
43                 result=0;
44             }
45         %>
46         var show=document.getElementById("show");
47         if(<%=result%>==0)
48         {
49             show.innerText="操做失敗,即將返回主頁……";
50         }
51         else
52         {
53             show.innerText="學生信息刪除成功,即將返回主頁……";
54         }
55     }
56 </script>
57 </head>
58 <body onload="Onload()">
59 <%   response.setHeader("Refresh", "2;url=lessonmag.jsp?index=1"); %>
60     <h2 id="show"></h2>
61 </body>
62 </html>
View Code

接下來是學籍管理頁面

主頁代碼:

  1 <%@page import="com.stumag.javabean.Status"%>
  2 <%@page import="java.util.ArrayList"%>
  3 <%@page import="com.stumag.javabean.Password"%>
  4 <%@page import="java.util.List"%>
  5 <%@page import="com.stumag.util.DBUtil"%>
  6 <%@ page language="java" contentType="text/html; charset=GB18030"
  7     pageEncoding="GB18030"%>
  8 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  9 <!DOCTYPE html>
 10 <html>
 11 <head>
 12 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
 13 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
 14 <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
 15 <script type="text/javascript" src="jquery.min.js"></script>
 16 <script type="text/javascript" src="jquery.bumpytext.packed.js"></script>
 17 <script type="text/javascript" src="easying.js"></script>
 18 <script type="text/javascript">
 19     //<![CDATA[
 20     $(document).ready(function() {
 21         $('p#example').bumpyText();
 22     });            //]]>
 23     
 24     $(document).ready(function() {
 25     });
 26 </script>
 27 <title>學籍管理</title>
 28 <style type="text/css">
 29     *{
 30         margin:0px;
 31         padding:0px;
 32     }
 33     .head {
 34     background-color: #66CCCC;
 35     text-align: center;
 36     position: relative;
 37     height: 100px;
 38     width: 100;
 39     text-shadow: 5px 5px 4px Black;
 40     }
 41     
 42     .wrap{
 43     width:100;
 44     height:764px;
 45     }
 46     
 47     .foot {
 48     width: 100;
 49     height:200px;
 50     background-color:#CC9933;
 51     position: relative;
 52     text-align:center;
 53     }
 54     .title {    
 55     font-family: "宋體";    
 56     color: #FFFFFF;    
 57     position: absolute;    
 58     top: 50%;    
 59     left: 50%;    
 60     transform: translate(-50%, -50%);  /* 使用css3的transform來實現 */    
 61     font-size: 36px;    
 62     height: 40px;    
 63     width: 30%;
 64     } 
 65     .power {    
 66     font-family: "宋體";
 67     color: #FFFFFF;    
 68     position: absolute;    
 69     top: 50%;
 70     left: 50%;    
 71     transform: translate(-50%, -50%);  
 72     height: 60px;
 73     width: 40%;    
 74     align-content:center;
 75     }     
 76     .foot .power .information {    
 77     width: 100%;    
 78     height: 24px;    
 79     position: relative;
 80     }
 81     .foot .power p {
 82     height: 24px;    
 83     width: 100%;
 84     }
 85     .wrap .nav .navbar{
 86     text-align:center;
 87     text-size:10px;
 88     }
 89     .nav { float: left; clear: both; width: 15%; margin: auto; height:764px; background: #eee; }
 90     .nav ul { list-style: none; margin: 0px; padding: 0px; }
 91     .nav li { float: none; width: 100%; }
 92     .nav li a { display: block; width: 100%; padding: 20px; border-left: 5px solid; position: relative; z-index: 2; text-decoration: none; color: #444; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; }
 93     .nav li a:hover { border-bottom: 0px; color: #fff; }
 94     .nav li:first-child a { border-left: 10px solid #3498db; }
 95     .nav li:nth-child(2) a { border-left: 10px solid #ffd071; }
 96     .nav li:nth-child(3) a { border-left: 10px solid #f0776c; }
 97     .nav li:nth-child(4) a { border-left: 10px solid #9370db; }
 98     .nav li:nth-child(5) a { border-left: 10px solid #9acd32; }
 99     .nav li:nth-child(6) a { border-left: 10px solid #888888; }
100     .nav li:last-child a { border-left: 10px solid #1abc9c; }
101     .nav li a:after { content: ""; height: 100%; left: 0; top: 0; width: 0px; position: absolute; transition: all 0.3s ease 0s; -webkit-transition: all 0.3s ease 0s; z-index: -1; }
102     .nav li a:hover:after { width: 100%; }
103     .nav li:first-child a:after { background: #3498db; }
104     .nav li:nth-child(2) a:after { background: #ffd071; }
105     .nav li:nth-child(3) a:after { background: #f0776c; }
106     .nav li:nth-child(4) a:after { background: #9370db; }
107     .nav li:nth-child(5) a:after { background: #9acd32; }
108     .nav li:nth-child(6) a:after { background: #888888; }
109     .nav li:last-child a:after { background: #1abc9c; }
110 
111     .nav li:nth-child(3) a{ background: #f0776c; }
112     
113     .clearfix {display: inline-block;}
114     .clearfix {display: block;}
115     #example{margin-top:-40px;}
116     .bumpy-char {
117     line-height: 3.4em;
118     position: relative;
119     }
120     
121     .wrap .show{
122     position:relative;
123     height:764px;
124     width:85%;
125     float:right;
126     background-size:cover;
127     overflow-y :auto;
128     }
129     
130     .wrap .show .teacherinformation{
131     position:relative;
132     margin-top:20px;
133     margin-bottom:20px;
134     margin-left:auto;
135     margin-right:auto;
136     width:100%;
137     text-align:center;
138     }
139     
140     .userpwd tr{
141     text-align:center;
142     }
143     .userpwd tr th
144     {
145         padding-top:10px;
146         padding-bottom:10px;
147         padding-left:30px;
148         padding-right:30px;
149         text-align:center;
150     }
151     .userpwd tr td
152     {
153         padding-top:10px;
154         padding-bottom:10px;
155         padding-left:30px;
156         padding-right:30px;
157     }
158     
159     .wrap .show div .pagenavbox
160     {
161         position:relative;
162     }
163     
164     .pagenav
165     {
166         list-style:none;
167         width:700px;
168         height:50px;
169         float:left;
170     }
171     .pagenav li
172     {
173         float:left;
174         height:50px;
175         width:50px;
176         margin-left:20px;
177         border-radius:8px;
178         background-color:#99FFCC;
179         line-height:50px;
180     }
181     .pagenav li a
182     {
183         text-decoration:none;
184         display:block;
185         height:50px;
186         cursor:pointer;
187     }
188     .pagenav li a:hover{
189         background-color:#99FFFF;
190         color:black;
191         border-radius:8px;
192     }
193     .wrap .show div .pagenavbox .jumptip
194     {
195         float:left;
196         text-align:center;
197         font-size:16px;
198         overflow:hidden;
199         margin-left:20px;
200         padding-top:10px;
201     }
202     .wrap .show div .pagenavbox .jumptip .jumpto
203     {
204         width:50px;
205         height:<
相關文章
相關標籤/搜索