学生信息管理系统 1.0

学生信息管理系统V1.0

1.实现用户的注册与登录功能。

    1.1:注册时检测用户名,如果有重复则需要重新输入,用户信息存入数据库。

    1.2:登录时,有验证码验证。

2.实现用户查询学生表的基本信息。

3.用户可以更改、删除学生表信息。

4.系统可以正确显示系统时间。

5.系统正确显示用户权限(功能暂未实现)。

因为很多东西还没有学到,只能用最基础的代码实现功能.

 

1)欢迎页面

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 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=UTF-8">
 7 <title>欢迎页面</title>
 8 </head>
 9 <body>
10 <%
11 session.invalidate();//销毁session
12 
13 %>
14 <table width="900" cellpadding="0" cellspacing="0" border="0" align="center">
15 <tr><td>
16 <img src="D:\123\Java\workspace\denglu\images\1.jpg" usemap="#tupian" />
17 <map name="tupian">
18     <area shape="rect" coords="190,90,270,140" href="zhuce.jsp" />
19     <area shape="rect" coords="600,90,690,140" href="denglu.jsp" />
20 </map>
21 </td></tr>
22 </table>
23 <div id="aa"></div>
24 </body> 
25 </html>
View Code

显示效果:

2)注册界面:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 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=UTF-8">
 7 <title>注册</title>
 8 </head>
 9 <body>
10 
11 <form action="Testzhuce" method="post"> 
12 
13 <table width="800" height="520" border="0" align="center" cellpadding="0" cellspacing="0" style="background-color: #f2eada">
14    <tr height="40" align="center">
15        <td colspan="4" style="background-color: blue"></td></tr>
16    <tr height="20"><td colspan="4"></td></tr>
17    <tr>
18        <td width="29"></td>
19        <td width="450" align="left" >
20            <h1>TF</h1>
21            <h2>学生信息管理系统V1.0</h2>
22            <h4>STUDENG INFORMATION MANAGEMENT SYSTEM</h4>
23            
24        </td>
25        <td width="1" bgcolor="black"></td>
26        <td width="320" height="360">
27            <table width="320" height="360" border="0">
28               <tr height="60" align="left">
29                  <td colspan="2"><h2>&nbsp;&nbsp;账户注册</h2></td></tr>
30               <tr height="30">
31                  <td width="80" align="right">用户名</td>
32                  <td align="left"><input type="text" name="username"></td></tr>
33               <tr height="30">
34                  <td width="80" align="right">&nbsp;&nbsp;</td>
35                  <td align="left"><input type="password" name="password1"></td></tr>  
36               <tr height="30">
37                  <td width="80" align="right">确认密码</td>
38                  <td align="left"><input type="password" name="password2"></td></tr>
39               <tr height="30">
40                  <td width="80" align="right">&nbsp;&nbsp;</td>
41                  <td align="left"><input type="radio" name="sex" value="男">42                  <input type="radio" name="sex" value="女"></td></tr>
43               <tr height="30">
44                  <td align="center" colspan="2">
45                  <textarea cols="20" rows="5">安全管理事项 </textarea></td></tr>    
46               <tr height="30">
47                  <td align="center" colspan="2"><input type="checkbox" name="tongyi" value="1">同意《安全管理事项》</td></tr>
48               <tr align="center">
49                  <td colspan="2"><input style="width: 80px" type="submit" value="提交"></td></tr>  
50                       
51            </table>
52        </td>
53    </tr> 
54    <tr height="20">
55        <td colspan="4"></td></tr>
56    <tr height="80" bgcolor="blue">
57        <td colspan="4" align="center"><h4>学生信息管理系统V1.0版 Copyright@2016-2017&nbsp;&nbsp;玛雅网络工作室&nbsp;&nbsp; 版权所有</h4></td></tr>  
58        
59  </table>
60 
61 </form>
62 </body>
63 </html>
View Code

显示效果:

3)登录页面:

 1 <%@page import="com.sp.web.Yanzhengma"%>
 2 <%@ page language="java" contentType="text/html; charset=UTF-8"
 3     pageEncoding="UTF-8"%>
 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=UTF-8">
 8 <title>系统登录</title>
 9 </head>
10 <body>
11 <%
12 Yanzhengma yan = new Yanzhengma();
13 String str = yan.printYXM();
14 session.setAttribute("yanzhengma", str);
15 %>
16 <form action="Testdenglu" method="post"> 
17 <table width="800" height="520" border="0" align="center" cellpadding="0" cellspacing="0" style="background-color: #f2eada">
18    <tr height="40" align="center">
19        <td colspan="4" style="background-color: blue"></td></tr>
20    <tr height="120">
21        <td colspan="4"></td></tr>
22    <tr>
23        <td width="29"></td>
24        <td width="450" align="left" >
25            <h1>TF</h1>
26            <h2>学生信息管理系统V1.0</h2>
27            <h4>STUDENG INFORMATION MANAGEMENT SYSTEM</h4>
28            <ol>
29               <li>完善的功能平台,实现信息一体化管理。</li>
30               <li>安全的系统管理模式,实现权限划分和登录控制</li>
31               <li>可扩展的接口,使用需求扩展和功能模块扩展</li>
32            </ol>
33        </td>
34        <td width="1" bgcolor="black"></td>
35        <td width="320" height="240">
36            <table width="320" height="240" border="0">
37               <tr height="60" align="left">
38                  <td colspan="2"><h2>&nbsp;&nbsp;系统登录</h2></td></tr>
39               <tr height="40">
40                  <td width="80" align="right">用户名</td>
41                  <td align="left"><input type="text" name="username"></td></tr>
42               <tr height="40">
43                  <td width="80" align="right">&nbsp;&nbsp;</td>
44                  <td align="left"><input type="password" name="password"></td></tr>  
45               <tr height="40">
46                  <td width="80" align="right">验证码</td>
47                  <td align="left"><input type="text" name="yanzhengma" style="width: 60px"><%= "&nbsp;" + str %>
48                  <a href="denglu.jsp">&nbsp;&nbsp;看不清?</a></td></tr>                
49               <tr align="center">
50                  <td colspan="2"><input style="width: 80px" type="submit" value="登录"></td></tr>            
51            </table>
52        </td>
53    </tr> 
54    <tr height="40">
55        <td colspan="4"></td></tr>
56    <tr height="80" bgcolor="blue">
57        <td colspan="4" align="center"><h4>学生信息管理系统V1.0版 Copyright@2016-2017&nbsp;&nbsp;玛雅网络工作室&nbsp;&nbsp; 版权所有</h4></td></tr>  
58        
59  </table>
60 </form>
61 </body>
62 </html>
View Code

显示效果:

4)功能页面展示:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8" import="java.util.*" import="java.text.SimpleDateFormat"%>
 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=UTF-8">
 7 <title>主页面</title>
 8 </head>
 9 <body>
10 <%
11 String str1 = "";
12 String str2 ="";
13 Object obj = session.getAttribute("username");
14 if(obj != null){
15     str1 = obj.toString();
16     if(str1.equals("唐枫")){
17         str2 = "系统管理员";
18     }else if(str1.equals("张三")){
19         str2 = "代理老师";
20     }else{
21         str2 = "学生";
22     }
23 }else{
24     out.println("登录超时,请重新登录"); 
25     response.setHeader("refresh", "5;URL=denglu.jsp");
26 }
27 
28 %>
29 <table width="900" height="60" border="0" cellpadding="0" cellspacing="0" bgcolor="#009ad6" align="center">
30    <tr><td>
31      <table height="40" width="900" border="0" cellpadding="0" cellspacing="0">
32        <tr height="40" style="font-size: 28px;">
33           <td width="30"></td>
34           <td width="300"><font color="#fffef9">学生信息管理系统V1.0</font></td>
35           <td></td>
36           <td width="60" style="font-size: 15px" align="right"><a href="yemian.jsp">退出系统</a></td>
37      </table>  
38    </td></tr>
39    <tr><td>
40      <table height="20" width="900" border="0" cellpadding="0" cellspacing="0">
41        <tr style="font-size: 12px">
42           <td width="30"></td>
43           <td width="300">STUDENG INFORMATION MANAGEMENT SYSTEM</td>
44           <td></td>
45           <td width="100" align="left"><%= "登录账户:" + str1 %></td>
46           <td width="1" bgcolor="black"></td>
47           <td width="120" align="center">权限:<%= str2 %></td>
48           <td width="1" bgcolor="black"></td>
49           <td width="150" align="right">系统时间:<span id="bb"></span></td></tr>
50      </table>
51    </td></tr>
52     <tr><td>
53      <table width="900" border="0" cellpadding="0" cellspacing="0" bgcolor="#feeeed">
54        <tr><td height="60"></td></tr>
55        <tr align="center"><td><a href="addStu.jsp">学生信息添加</a></td></tr>
56        <tr><td height="30"></td></tr>
57        <tr align="center"><td><a href="index.jsp">学生信息查询/修改</a></td></tr>
58        <tr><td height="30"></td></tr>  
59      </table>
60    </td></tr>
61 </table>
62 
63 
64 
65 </body>
66 </html>
67 <script language="javascript">
68 function showtime()
69 {
70     var tt = document.getElementById("bb");
71     var time = new Date();
72     var y = time.getFullYear();
73     var MM = time.getMonth() + 1;
74     var d = time.getDate();
75     var h = time.getHours();
76     var m = time.getMinutes();
77     var s = time.getSeconds();
78     var str = y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
79     tt.innerHTML = str;
80     window.setTimeout("showtime()", 1000);
81 }
82     window.setTimeout("showtime()",0);
83 </script>
View Code

效果展示:

5)添加学生信息

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 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=UTF-8">
 7 <title>添加学生信息</title>
 8 </head>
 9 <body>
10 <%
11 String str1 = "";
12 String str2 ="";
13 Object obj = session.getAttribute("username");
14 if(obj != null){
15     str1 = obj.toString();
16     if(str1.equals("唐枫")){
17         str2 = "系统管理员";
18     }else if(str1.equals("张三")){
19         str2 = "代理老师";
20     }else{
21         str2 = "学生";
22     }
23 }else{
24     out.println("登录超时,请重新登录"); 
25     response.setHeader("refresh", "5;URL=denglu.jsp");
26 }
27 
28 %>
29 <table width="900" height="60" border="0" cellpadding="0" cellspacing="0" bgcolor="#009ad6" align="center">
30    <tr><td>
31      <table height="40" width="900" border="0" cellpadding="0" cellspacing="0">
32        <tr height="40" style="font-size: 28px;">
33           <td width="30"></td>
34           <td width="300"><font color="#fffef9">学生信息管理系统V1.0</font></td>
35           <td></td>
36           <td width="60" style="font-size: 15px" align="right"><a href="yemian.jsp">退出系统</a></td>
37      </table>  
38    </td></tr>
39    <tr><td>
40      <table height="20" width="900" border="0" cellpadding="0" cellspacing="0">
41        <tr style="font-size: 12px">
42           <td width="30"></td>
43           <td width="300">STUDENG INFORMATION MANAGEMENT SYSTEM</td>
44           <td></td>
45           <td width="100" align="left"><%= "登录账户:" + str1 %></td>
46           <td width="1" bgcolor="black"></td>
47           <td width="120" align="center">权限:<%= str2 %></td>
48           <td width="1" bgcolor="black"></td>
49           <td width="150" align="right">系统时间:<span id="bb"></span></td></tr>
50      </table>
51    </td></tr>
52    <tr><td>
53       <table height="20" width="900" border="1" cellpadding="0" cellspacing="0" bgcolor="#feeeed">
54          <tr><td height="60"></td></tr>
55          <tr style="font-size:36px;" align="center"><td>学生信息录入</td></tr>
56          <tr align="center">
57            <td height="50" width="450">
58              <form action="SaveStudent" method="post">
59                                            学号:<input type="text" name="sno"><br>
60                                            姓名:<input type="text" name="sname"><br>
61                                            性别:<input type="text" name="ssex"><br>
62                                           生日:<input type="text" name="sbirthday"><br>
63                                           班级:<input type="text" name="class"><br>
64               <input type="submit" value="保存">
65             </form></td>
66         </tr>
67       </table></td></tr>
68 </table>
69 
70 
71 
72 </body>
73 </html>
74 <script language="javascript">
75 function showtime()
76 {
77     var tt = document.getElementById("bb");
78     var time = new Date();
79     var y = time.getFullYear();
80     var MM = time.getMonth();
81     var d = time.getDay();
82     var h = time.getHours();
83     var m = time.getMinutes();
84     var s = time.getSeconds();
85     var str = y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
86     tt.innerHTML = str;
87     window.setTimeout("showtime()", 1000);
88 }
89     window.setTimeout("showtime()",0);
90 </script>
View Code

效果:

6)学生信息查询

 1 <%@page import="com.sp.web.CX" import="com.sp.web.Student"%>
 2 <%@page import="java.text.SimpleDateFormat"%>
 3 <%@ page language="java" contentType="text/html; charset=UTF-8"
 4     pageEncoding="UTF-8" import="java.sql.*" import="java.util.*"%>
 5 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 6 <html>
 7 <head>
 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 9 <title>学生信息</title>
10 </head>
11 <body>
12 <%
13 String str1 = "";
14 String str2 ="";
15 Object obj = session.getAttribute("username");
16 if(obj != null){
17     str1 = obj.toString();
18     if(str1.equals("唐枫")){
19         str2 = "系统管理员";
20     }else if(str1.equals("张三")){
21         str2 = "代理老师";
22     }else{
23         str2 = "学生";
24     }
25 }else{
26     out.println("登录超时,请重新登录"); 
27     response.setHeader("refresh", "5;URL=denglu.jsp");
28 }
29 
30 %>
31 <table width="900" height="60" border="0" cellpadding="0" cellspacing="0" bgcolor="#009ad6" align="center">
32    <tr><td>
33      <table height="40" width="900" border="0" cellpadding="0" cellspacing="0">
34        <tr height="40" style="font-size: 28px;">
35           <td width="30"></td>
36           <td width="300"><font color="#fffef9">学生信息管理系统V1.0</font></td>
37           <td></td>
38           <td width="60" style="font-size: 15px" align="right"><a href="yemian.jsp">退出系统</a></td>
39      </table>  
40    </td></tr>
41    <tr><td>
42      <table height="20" width="900" border="0" cellpadding="0" cellspacing="0">
43        <tr style="font-size: 12px">
44           <td width="30"></td>
45           <td width="300">STUDENG INFORMATION MANAGEMENT SYSTEM</td>
46           <td></td>
47           <td width="100" align="left"><%= "登录账户:" + str1 %></td>
48           <td width="1" bgcolor="black"></td>
49           <td width="120" align="center">权限:<%= str2 %></td>
50           <td width="1" bgcolor="black"></td>
51           <td width="150" align="right">系统时间:<span id="bb"></span></td></tr>
52      </table>
53    </td></tr>
54    <tr><td>
55      <table height="20" width="900" border="1" cellpadding="0" cellspacing="0" bgcolor="#feeeed">
56         <tr><td height="60" colspan="6"></td></tr>
57         <tr style="font-size: 36px" align="center"><td height="40" colspan="6">学生信息表</td></tr>
58         <tr align="center">
59             <td width="150">学号</td>
60             <td width="150">姓名</td>
61             <td width="150">性别</td>
62             <td width="150">出生日期</td>
63             <td width="150">班级</td>
64             <td>操作</td>
65      <%
66      CX cx = new CX();
67      List<Student> list = cx.chaxun();
68      for (Student ft : list) {%>
69      <tr align="center">
70         <td><%=ft.getSno() %></td>
71         <td><%=ft.getSname() %></td>
72         <td><%= ft.getSsex() %></td>
73         <td><%= ft.getSbirthday() %></td>
74         <td><%= ft.getSclass() %></td>
75         <td><%= ft.getCaozuo() %></tr>
76         <%} %>
77      </table>
78    </td></tr>
79 </table>
80 </body>
81 </html>
82 <script language="javascript">
83 function showtime()
84 {
85     var tt = document.getElementById("bb");
86     var time = new Date();
87     var y = time.getFullYear();
88     var MM = time.getMonth()+1;
89     var d = time.getDate();
90     var h = time.getHours();
91     var m = time.getMinutes();
92     var s = time.getSeconds();
93     var str = y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
94     tt.innerHTML = str;
95     window.setTimeout("showtime()", 1000);
96 }
97     window.setTimeout("showtime()",0);
98 </script>
View Code

效果:

7)学生信息修改

  1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2     pageEncoding="UTF-8"%>
  3     <%@ page  import="java.sql.*" import="java.text.SimpleDateFormat" %>
  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=UTF-8">
  8 <title>信息修改页面</title>
  9 </head>
 10 <body>
 11 <%
 12 //接收主键,从数据库中读取最新数据,进行修改
 13 
 14 String sno = request.getParameter("sno");
 15 String sname = "",ssex = "",sbirthday = "",sclass = "";
 16 if(sno != null && sno.trim().length() > 0) {
 17     //从数据库读取数据
 18     try{
 19          Class.forName("oracle.jdbc.driver.OracleDriver");
 20          Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:SP","test","123");
 21         PreparedStatement ps = c.prepareStatement("select * from student where sno = ?");
 22         ps.setString(1, sno);
 23         ResultSet rs = ps.executeQuery();
 24         if(rs != null && rs.next()){
 25             
 26                 sname = rs.getString("sname");
 27                 ssex =  rs.getString("ssex");
 28                 try {
 29                 SimpleDateFormat std = new SimpleDateFormat("yyyy/MM/dd");
 30                 sbirthday = std.format(rs.getDate("sbirthday"));
 31                 } catch (Exception ex) {
 32                 }
 33                 sclass = rs.getString("class");
 34                 rs.close();
 35                 
 36         } else {
 37             out.println("未能找到符合条件的任何数据");
 38         }
 39         ps.close();
 40         c.close();
 41         }catch(Exception e){
 42             e.printStackTrace();
 43         }
 44 } else {
 45     out.println("请正确访问");
 46 }
 47 
 48 %>
 49 <%
 50 String str1 = "";
 51 String str2 ="";
 52 Object obj = session.getAttribute("username");
 53 if(obj != null){
 54     str1 = obj.toString();
 55     if(str1.equals("唐枫")){
 56         str2 = "系统管理员";
 57     }else if(str1.equals("张三")){
 58         str2 = "代理老师";
 59     }else{
 60         str2 = "学生";
 61     }
 62 }else{
 63     out.println("登录超时,请重新登录"); 
 64     response.setHeader("refresh", "5;URL=denglu.jsp");
 65 }
 66 
 67 %>
 68 <table width="900" height="60" border="0" cellpadding="0" cellspacing="0" bgcolor="#009ad6" align="center">
 69    <tr><td>
 70      <table height="40" width="900" border="0" cellpadding="0" cellspacing="0">
 71        <tr height="40" style="font-size: 28px;">
 72           <td width="30"></td>
 73           <td width="300"><font color="#fffef9">学生信息管理系统V1.0</font></td>
 74           <td></td>
 75           <td width="60" style="font-size: 15px" align="right"><a href="yemian.jsp">退出系统</a></td>
 76      </table>  
 77    </td></tr>
 78    <tr><td>
 79      <table height="20" width="900" border="0" cellpadding="0" cellspacing="0">
 80        <tr style="font-size: 12px">
 81           <td width="30"></td>
 82           <td width="300">STUDENG INFORMATION MANAGEMENT SYSTEM</td>
 83           <td></td>
 84           <td width="100" align="left"><%= "登录账户:" + str1 %></td>
 85           <td width="1" bgcolor="black"></td>
 86           <td width="120" align="center">权限:<%= str2 %></td>
 87           <td width="1" bgcolor="black"></td>
 88           <td width="150" align="right">系统时间:<span id="bb"></span></td></tr>
 89      </table>
 90    </td></tr>
 91    <tr><td>
 92       <table height="20" width="900" border="1" cellpadding="0" cellspacing="0" bgcolor="#feeeed">
 93          <tr><td height="60"></td></tr>
 94          <tr style="font-size:36px;" align="center"><td>学生信息修改</td></tr>
 95          <tr align="center">
 96            <td height="50" width="450">
 97             <form action="SaveStudent" method="post">
 98 学号:<input type="text" name="sno" value="<%= sno %>" readonly="readonly"><br>
 99 姓名:<input type="text" name="sname" value="<%= sname %>"><br>
100 性别:<input type="text" name="ssex" value="<%= ssex %>"><br>
101 生日:<input type="text" name="sbirthday" value="<%= sbirthday %>"><br>
102 班级:<input type="text" name="class" value="<%= sclass%>"><br>
103 <input type="hidden" name="isupdate" value="1">
104 
105 <input type="submit" value="保存">
106 </form></td>
107         </tr>
108       </table></td></tr>
109    </table>
110 </body>
111 </html>
112 <script language="javascript">
113 function showtime()
114 {
115     var tt = document.getElementById("bb");
116     var time = new Date();
117     var y = time.getFullYear();
118     var MM = time.getMonth() + 1;
119     var d = time.getDate();
120     var h = time.getHours();
121     var m = time.getMinutes();
122     var s = time.getSeconds();
123     var str = y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
124     tt.innerHTML = str;
125     window.setTimeout("showtime()", 1000);
126 }
127     window.setTimeout("showtime()",0);
128 </script>
View Code

展示效果与录入信息效果基本相似。

后台处理程序:

首先建立学生信息类,属性名对应表格字段名,不做展示,查询信息显示,常见List集合,把查询到的每一条记录实例化为学生信息类存入集合中:

 1 package com.sp.web;
 2 
 3 import java.sql.*;
 4 import java.util.*;
 5 //import java.text.SimpleDateFormat;
 6 import com.sp.web.Student;
 7 
 8 public class CX {
 9     public List<Student> chaxun() {
10         List<Student> list = new ArrayList<Student>();
11         ResultSet rs = null;
12 
13         try {
14             // 1.链接数据库
15             // a. 加载驱动
16             Class.forName("oracle.jdbc.driver.OracleDriver");
17             // b. 得到连接
18             Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:SP", "test", "123");
19             // 2.读取
20             Statement st = c.createStatement();
21             // 3.输出结果集
22             rs = st.executeQuery("select * from student");
23             if (rs != null) {
24                 //SimpleDateFormat std = new SimpleDateFormat("MM-dd-yyyy");
25                 while (rs.next()) {
26                     Student stu = new Student();
27                     stu.setSno(rs.getString("sno"));
28                     stu.setSname(rs.getString("sname"));
29                     stu.setSsex(rs.getString("ssex"));
30                     stu.setSbirthday(rs.getDate("sbirthday"));
31                     stu.setSclass(rs.getString("class"));
32                     stu.setCaozuo("<a href='updatestu.jsp?sno=" + rs.getString("sno")
33                     + "'>[修改]</a><a href='DeleteStu?sno=" + rs.getString("sno") + "'>[删除]</a><br>");
34                     list.add(stu);
35                 }
36             }
37 
38             // 4.释放资源
39             rs.close();
40             st.close();
41             c.close();
42         } catch (Exception e) {
43             e.printStackTrace();
44         }
45         return list;
46     }
47 
48     public static void main(String[] args) {
49 
50         
51     }
52 
53 }
View Code

学生信息保存与修改,使用共同的处理程序,只是数据库操作语句略有不同:

 1 package com.sp.web;
 2 
 3 import java.io.IOException;
 4 import java.sql.*;
 5 import java.text.SimpleDateFormat;
 6 
 7 import javax.servlet.ServletException;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 
12 public class SaveStudent extends HttpServlet {
13     private static final long serialVersionUID = 1L;
14 
15     public SaveStudent() {
16         super();
17 
18     }
19 
20     protected void doGet(HttpServletRequest request, HttpServletResponse response)
21             throws ServletException, IOException {
22         // 处理保存数据请求
23         // 1.接收参数
24         String sno = request.getParameter("sno").trim();
25         String sname = request.getParameter("sname").trim();
26         String ssex = request.getParameter("ssex").trim();
27         String sbirthday = request.getParameter("sbirthday").trim();
28         String sclass = request.getParameter("class").trim();
29         String isup = request.getParameter("isupdate");
30         // 2.验证
31         if (sno != null && sno.trim().length() != 0) {
32             try {    
33                 Class.forName("oracle.jdbc.driver.OracleDriver");            
34                 Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:SP", "test", "123");
35                 PreparedStatement pst = c
36                         .prepareStatement("insert into student (sname,ssex,sbirthday,class,sno) values(?,?,?,?,?)");
37                 if(isup != null && isup.equals("1")){
38                     pst = c
39                             .prepareStatement("update student set sname = ?,ssex = ?,sbirthday = ?,class = ? where " + "sno = ?");
40                 }                
41                 pst.setString(1, sname);
42                 pst.setString(2, ssex);                
43                 //String转成Date型  日期格式的类,可以进行日期转换
44                 SimpleDateFormat sd = new SimpleDateFormat("yyyy/MM/dd");
45                 java.util.Date date = sd.parse(sbirthday);
46                 //使用Long型的时间构造SQL时间
47                 Date tdate = new Date(date.getTime());
48                 pst.setDate(3, tdate);                
49                 pst.setString(4, sclass);
50                 pst.setString(5, sno);
51                 pst.executeUpdate();
52                
53                 pst.close();
54                 c.close();
55             
56                 response.getWriter().write("数据保存成功");  
57                 response.setHeader("refresh", "3;URL=index.jsp");
58             } catch (Exception e) {
59                 e.printStackTrace();
60                 response.getWriter().write("数据保存失败");
61                 response.setHeader("refresh", "3;URL=index.jsp");
62             }
63             
64         } else {
65             response.getWriter().write("请正确提交数据");
66             response.setHeader("refresh", "3;URL=index.jsp");
67         }
68 
69     }
70 
71     protected void doPost(HttpServletRequest request, HttpServletResponse response)
72             throws ServletException, IOException {
73 
74         doGet(request, response);
75     }
76 
77 }
View Code

2.0计划:

1:教师表的增删改查

2:任务1达成之后,实现权限划分

posted @ 2016-07-08 08:10  唐枫  阅读(526)  评论(0编辑  收藏  举报