学生身体体质管理信息系统

 

 

 1 //index_stu.jsp
 2 
 3 <%@ page language="java" pageEncoding="UTF-8"%>
 4 <html>
 5 <head>
 6 <title>页面标题</title>
 7 </head>
 8 <frameset rows="80,*">
 9 <frame src="index_stu_title.jsp"scroling="no"> 
10 <frameset cols="140,*">
11 <frame src="index_stu_left.jsp"scroling="no">
12 <frame src="index_stu_right.jsp"name="right"scroling="no">
13 </frameset>
14 </frameset>
15 </html>
index_stu.jsp

 

 1 //index_stu_title.jsp
 2 
 3 <%@ page language="java" pageEncoding="UTF-8"%>
 4 <html>
 5 <head>
 6 <title>页面标题</title>
 7 </head>
 8 <body>
 9 <center>
10 <h1>学生身体体质信息管理系统</h1>
11 </center>
12 </body>
13 </html>
index_stu_title.jsp

 

 1 //index_stu_left.jsp
 2 
 3 <%@ page language="java" pageEncoding="UTF-8"%>
 4 <html>
 5 <head>
 6 <title>菜单页面</title>
 7 </head>
 8 <body>
 9 <br><br><br><br><br><br>
10 <p><a href="find_stu_1.jsp"target="right">列出全部学生</a></p>
11 <p><a href="find_stu_3_tijiao.jsp"target="right">按条件查询学生</a></p>
12 <p><a href="insert_stu_2_tijiao.jsp"target="right">新添加学生</a></p>
13 <p><a href="delete_stu_2_tijiao.jsp"target="right">按条件删除学生</a></p>
14 <p><a href="update_stu_2_tijiao.jsp"target="right">按条件修改学生</a></p>
15 </body>
16 </html>
index_stu_left.jsp
 1 //index_stu_right.jsp
 2 
 3 <%@ page language="java" pageEncoding="UTF-8"%>
 4 <html>
 5 <head>
 6 <title>信息显示页面</title>
 7 </head>
 8 <body background="image/2.jsp">
 9 
10 </body>
11 </html>
index_stu_right.jsp

 

 

 1 //find_stu_1.jsp
 2 
 3 <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
 4 <html>
 5 <title>显示所有学生页面</title>    
 6 <body>
 7 <center>
 8 <%
 9 String driverName="com.mysql.jdbc.Driver";
10 String userName="root";
11 String userPwd="184896";
12 String dbName="students";
13 String url1="jdbc:mysql://localhost:3306/"+dbName;
14 String url2="?user="+userName+"&password="+userPwd;
15 String url3="&useUnicode=true&characterEncoding=UTF-8";
16 String url=url1+url2+url3;
17 Class.forName(driverName);
18 Connection conn=DriverManager.getConnection(url);
19 
20 
21 String sql="select * from stu_info";
22 PreparedStatement pstmt=conn.prepareStatement(sql);
23 ResultSet rs = pstmt.executeQuery();
24 rs.last();
25 %>你要查询的学生数据表中共有
26 <font size="5"color="red"><%=rs.getRow()%></font>27 <table border="2"bgcolor="ccceee"width="650">
28 <tr bgcolor="CCCCCC"align="center">
29 <td>记录条数</td>
30 <td>学号</td>
31 <td>姓名</td>
32 <td>性别</td>
33 <td>年龄</td>
34 <td>体重</td>
35 <td>身高</td>
36 </tr>
37 <% rs.beforeFirst();
38 while(rs.next())
39 {%>
40 <tr align="center">
41 <td><%=rs.getRow()%></td>
42 <td><%=rs.getString("id")%></td>
43 <td><%=rs.getString("name")%></td>
44 <td><%=rs.getString("sex")%></td>
45 <td><%=rs.getString("age")%></td>
46 <td><%=rs.getString("weight")%></td>
47 <td><%=rs.getString("hight")%></td>
48 </tr>
49 <%}%>
50 </table>
51 </center>
52 <% 
53 if(rs != null) {
54 rs.close();
55 }
56 if(pstmt!=null){pstmt.close();}
57 if(conn!=null){conn.close();}%>
58 </body>
59 </html>
find_stu_1.jsp

 

 

 1 //find_stu_3_tijiao.jsp
 2 
 3 <%@page language="java" pageEncoding="UTF-8"%>
 4 <html>
 5 <head> 
 6 <title>查询条件查询页面</title>
 7 <body>
 8 请选择查询条件<hr width="100%"size="3">
 9 <form action="find_stu_3.jsp">
10 性别:男<input type="radio"value="M"name="sex"checked="checked">
11 女<input type="radio"value="W"name="sex"><br><br>
12 体重范围:<p>&nbsp;&nbsp;&nbsp;&nbsp;
13 最小:<input type="text"name="w1"value="0"><br><br>
14 &nbsp;&nbsp;&nbsp;&nbsp;
15 最大:<input type="text"name="w2"value="150"></p>
16 <input type="submit"value="提 交">
17 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
18 <input type="reset"value="取 消">
19 </form>
20 
21 </body>
22 </html>
find_stu_3_tijiao.jsp

 

 1 //find_stu_3.jsp
 2 
 3 <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
 4 <html>
 5 <title>由提交页面获取查询条件并实现查询的页面</title>    
 6 <body>
 7 <center>
 8 <%
 9 String driverName="com.mysql.jdbc.Driver";
10 String userName="root";
11 String userPwd="184896";
12 String dbName="students";
13 String url1="jdbc:mysql://localhost:3306/"+dbName;
14 String url2="?user="+userName+"&password="+userPwd;
15 String url3="&useUnicode=true&characterEncoding=UTF-8";
16 String url=url1+url2+url3;
17 Class.forName(driverName);
18 Connection conn=DriverManager.getConnection(url);
19 
20 request.setCharacterEncoding("UTF-8");
21 String sex=request.getParameter("sex");
22 float weight1=Float.parseFloat(request.getParameter("w1"));
23 float weight2=Float.parseFloat(request.getParameter("w2"));
24 
25 String sql="select * from stu_info where sex=? and weight>=? and weight<=?";
26 PreparedStatement pstmt=conn.prepareStatement(sql);
27 pstmt.setString(1,sex);
28 pstmt.setFloat(2,weight1);
29 pstmt.setFloat(3,weight2);
30 ResultSet rs = pstmt.executeQuery(); 
31 rs.last();
32 %>你要查询的学生数据表中共有
33 <font size="5"color="red"><%=rs.getRow()%></font>34 <table border="2"bgcolor="ccceee"width="650">
35 <tr bgcolor="CCCCCC"align="center">
36 <td>记录条数</td>
37 <td>学号</td>
38 <td>姓名</td>
39 <td>性别</td>
40 <td>年龄</td>
41 <td>体重</td>
42 <td>身高</td>
43 </tr>
44 <% rs.beforeFirst();
45 while(rs.next())
46 {%>
47 <tr align="center">
48 <td><%=rs.getRow()%></td>
49 <td><%=rs.getString("id")%></td>
50 <td><%=rs.getString("name")%></td>
51 <td><%=rs.getString("sex")%></td>
52 <td><%=rs.getString("age")%></td>
53 <td><%=rs.getString("weight")%></td>
54 <td><%=rs.getString("hight")%></td>
55 </tr>
56 <%}%>
57 </table>
58 </center>
59 <% 
60 if(rs != null) {
61 rs.close();
62 }
63 if(pstmt!=null){pstmt.close();}
64 if(conn!=null){conn.close();}%>
65 </body>
66 </html>
find_stu_3.jsp

 

 1 //insert_stu_2_tijiao.jsp
 2 
 3 <%@page contentType="text/html" pageEncoding="UTF-8"%>
 4 <html>
 5 </head><title>添加任意学生的提交页面</title></head>
 6 
 7 <body>
 8 <form action="insert_stu_2.jsp" method="post">
 9 <table border="0"width="238"height="252">
10 <tr><td>学号</td><td><input type="text"name="id"></td></tr>
11 <tr><td>姓名</td><td><input type="text"name="name"></td></tr>
12 <tr><td>性别</td><td><input type="text"name="sex"></td></tr>
13 <tr><td>年龄</td><td><input type="text"name="age"></td></tr>
14 <tr><td>体重</td><td><input type="text"name="weight"></td></tr>
15 <tr><td>身高</td><td><input type="text"name="hight"></td></tr>
16 <tr align="center">
17 <td colspan="2">
18 <input type="submit"value="提 交">&nbsp;&nbsp;&nbsp;
19 <input type="reset"value="取 消 ">
20 </td>
21 </tr>
22 </table>
23 </form>
24 </body>
25 </html>
insert_stu_2_tijiao.jsp

 

 1 //insert_stu_2.jsp
 2 
 3 <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
 4 <html>
 5 </head><title>利用PreparedStatement对象添加一条记录页面</title></head>
 6 
 7 <body>
 8 <%String driverName="com.mysql.jdbc.Driver"; 
 9 String userName="root";
10 String userPwd="184896";
11 String dbName="students";
12 String url1="jdbc:mysql://localhost:3306/"+dbName;
13 String url2="?user="+userName+"&password="+userPwd;
14 String url3="&userUnicode=true&characterEncoding=UTF-8";
15 String url=url1+url2+url3;
16 Class.forName(driverName);
17 Connection conn=DriverManager.getConnection(url);
18 
19 String sql="Insert into stu_info(id,name,sex,age,weight,hight)values(?,?,?,?,?,?)";
20 PreparedStatement pstmt=conn.prepareStatement(sql);
21 request.setCharacterEncoding("UTF-8");
22 int id=Integer.parseInt(request.getParameter("id"));
23 String name=request.getParameter("name");
24 String sex=request.getParameter("sex");
25 int age=Integer.parseInt(request.getParameter("age"));
26 float weight=Float.parseFloat(request.getParameter("weight"));
27 float hight=Float.parseFloat(request.getParameter("hight"));
28 
29 pstmt.setInt(1,id);
30 pstmt.setString(2,name);
31 pstmt.setString(3,sex);
32 pstmt.setInt(4,age);
33 pstmt.setFloat(5,weight);
34 pstmt.setFloat(6,hight);
35 int n=pstmt.executeUpdate();
36 if(n==1){%>数据插入操作成功!<br><%}
37 else{%>数据插入操作失败!<br><%}
38 if(pstmt!=null){pstmt.close();}
39 if(conn!=null){conn.close();}%>
40 </body>
41 </html>
insert_stu_2.jsp

 

 

 1 //update_stu_2_tijiao.jsp
 2 
 3 <%@ page language="java" pageEncoding="UTF-8"%>
 4 <html>
 5 <head> 
 6 <title>修改记录的条件提交页面</title>
 7 <body>
 8 请选择修改记录所满足的条件<hr width="100%"size="3">
 9 <form action="update_stu_2_edit.jsp"method="post"><br>
10 姓名:<input type="text"name="name"><br><br>
11 性别:男<input type="radio"value="M"name="sex">
12 女<input type="radio"value="W"name="sex"><br><br>
13 <input type="submit"value="提 交">
14 &nbsp;&nbsp;&nbsp;&nbsp;
15 <input type="reset"value="取 消">
16 </form>
17 
18 </body>
19 </html>
update_stu_2_tijiao.jsp

 

 1 //update_stu_2_edit.jsp
 2 
 3 <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
 4 <html>
 5 <title>修改编辑页面</title>    
 6 <body>
 7 <%
 8 String driverName="com.mysql.jdbc.Driver";
 9 String userName="root";
10 String userPwd="184896";
11 String dbName="students";
12 String url1="jdbc:mysql://localhost:3306/"+dbName;
13 String url2="?user="+userName+"&password="+userPwd;
14 String url3="&useUnicode=true&characterEncoding=UTF-8";
15 String url=url1+url2+url3;
16 Class.forName(driverName);
17 Connection conn=DriverManager.getConnection(url);
18 
19 request.setCharacterEncoding("UTF-8");
20 String sex=request.getParameter("sex");
21 String name=request.getParameter("name");
22 session.setAttribute("sex",sex);
23 session.setAttribute("name",name);
24 
25 
26 String sql="select * from stu_info where sex=? and name=?";
27 PreparedStatement pstmt=conn.prepareStatement(sql);
28 pstmt.setString(1,sex);
29 pstmt.setString(2,name);
30 ResultSet rs = pstmt.executeQuery();
31 if(rs.next())
32 {
33 int id=rs.getInt("id");
34 String name2=rs.getString("name");
35 String sex2=rs.getString("sex");
36 int age=rs.getInt("age");
37 float weight=rs.getFloat("weight");
38 float hight=rs.getFloat("hight");    
39 if(rs != null) {
40 rs.close();
41 }
42 if(pstmt!=null){pstmt.close();}
43 if(conn!=null){conn.close();}%>
44 <form action="update_stu_2.jsp"method="post">
45 <table border="0"width="238"height="252">
46 <tr><td>学号</td><td><input type="text"name="id"></td></tr>
47 <tr><td>姓名</td><td><input type="text"name="name"></td></tr>
48 <tr><td>性别</td><td><input type="text"name="sex"></td></tr>
49 <tr><td>年龄</td><td><input type="text"name="age"></td></tr>
50 <tr><td>体重</td><td><input type="text"name="weight"></td></tr>
51 <tr><td>身高</td><td><input type="text"name="hight"></td></tr>
52 <tr align="center">
53 <td colspan="2">
54 <input type="submit"value="提 交">&nbsp;&nbsp;&nbsp;
55 <input type="reset"value="取 消 ">
56 </td>
57 </tr>
58 </table>
59 </form>
60 <%}else{%>
61 没有找到合适条件的记录!!
62 <%
63 if(rs != null) {rs.close();}
64 if(pstmt!=null){pstmt.close();}
65 if(conn!=null){conn.close();}
66 }%>
67 </body>
68 </html>
update_stu_2_edit.jsp

 

 1 //update_stu_2.jsp
 2 
 3 <%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
 4 <html>
 5 <head> 
 6 <title>修改后重写记录页面</title>
 7 <body>
 8 <%
 9 String driverName="com.mysql.jdbc.Driver";
10 String userName="root";
11 String userPwd="184896";
12 String dbName="students";
13 String url1="jdbc:mysql://localhost:3306/"+dbName;
14 String url2="?user="+userName+"&password="+userPwd;
15 String url3="&useUnicode=true&characterEncoding=UTF-8";
16 String url=url1+url2+url3;
17 Class.forName(driverName);
18 Connection conn=DriverManager.getConnection(url);
19 
20 String sql="update stu_info set id=?,name=?,sex=?,age=?,weight=?,hight=? where name=? and sex=?"; 
21 PreparedStatement pstmt=conn.prepareStatement(sql); 
22 request.setCharacterEncoding("UTF-8");
23 int id=Integer.parseInt(request.getParameter("id"));
24 String name2=request.getParameter("name2");
25 String sex2=request.getParameter("sex2");
26 int age=Integer.parseInt(request.getParameter("age"));
27 
28 float weight=Float.parseFloat(request.getParameter("weight"));
29 float hight=Float.parseFloat(request.getParameter("hight"));
30 
31 String name=(String)session.getAttribute("name");
32 String sex=(String)session.getAttribute("sex");
33 
34 pstmt.setInt(1,id);
35 pstmt.setString(2,name);
36 pstmt.setString(3,sex);
37 pstmt.setInt(4,age);
38 pstmt.setFloat(5,weight);
39 pstmt.setFloat(6,hight); 
40 pstmt.setString(7,name);
41 pstmt.setString(8,sex);
42 int n=pstmt.executeUpdate();
43 if(n>=1){%>重写数据操作成功!<br><%}
44 else{%>重写数据操作失败!<%=n%><br><%}
45 if(pstmt!=null){pstmt.close();}
46 if(conn!=null){conn.close();}%>
47 </body>
48 </html>
update_stu_2.jsp

 

 

 1 //delete_stu_2_tijiao.jsp
 2 
 3 <%@page language="java" pageEncoding="UTF-8"%>
 4 <html>
 5 <head> 
 6 <title>删除条件查询页面</title>
 7 <body>
 8 请选择删除记录条件<hr width="100%"size="3">
 9 <form action="delete_stu_2.jsp">
10 性别:男<input type="radio"value="M"name="sex"checked="checked">
11 女<input type="radio"value="W"name="sex"><br><br>
12 体重范围:<p>&nbsp;&nbsp;&nbsp;&nbsp;
13 最小:<input type="text"name="w1"value="0"><br><br>
14 &nbsp;&nbsp;&nbsp;&nbsp;
15 最大:<input type="text"name="w2"value="150"></p>
16 <input type="submit"value="提 交">
17 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
18 <input type="reset"value="取 消">
19 </form>
20 
21 </body>
22 </html>
delete_stu_2_tijiao.jsp

 

 1 //delete_stu_2.jsp
 2 
 3 <%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
 4 <html>
 5 <head> 
 6 <title>利用提交条件删除记录页面</title>
 7 <body>
 8 <%
 9 String driverName="com.mysql.jdbc.Driver";
10 String userName="root";
11 String userPwd="184896";
12 String dbName="students";
13 String url1="jdbc:mysql://localhost:3306/"+dbName;
14 String url2="?user="+userName+"&password="+userPwd;
15 String url3="&useUnicode=true&characterEncoding=UTF-8";
16 String url=url1+url2+url3;
17 Class.forName(driverName);
18 Connection conn=DriverManager.getConnection(url);
19 request.setCharacterEncoding("UTF-8");
20 String name=request.getParameter("name");
21 String sex=request.getParameter("sex");
22 String ww1=request.getParameter("w1");
23 String ww2=request.getParameter("w2");
24 String s="1=1";
25 if(!name.equals(""))
26 s=s+"and name="+name+"";
27 if(sex!=null)
28 s=s+"and sex="+sex+"";
29 float w1,w2;
30 if(!ww1.equals("")){w1=Float.parseFloat(ww1);s=s+"and weight>="+w1;}
31 if(!ww2.equals("")){w2=Float.parseFloat(ww2);s=s+"and weight>="+w2;}
32 String sql="delete from stu_info where"+s;
33 PreparedStatement pstmt=conn.prepareStatement(sql); 
34 int n=pstmt.executeUpdate();
35 
36 if(n==1){%>数据删除操作成功!<br><%}
37 else{%>数据删除操作失败!<%=n%><br><%}
38 if(pstmt!=null){pstmt.close();}
39 if(conn!=null){conn.close();}%>
40 </body>
41 </html>
42 
43  
delete_stu_2.jsp

 

posted on 2017-10-22 22:50  小星_log  阅读(670)  评论(1编辑  收藏  举报