学生管理系统利用网页较为成熟的优化。。。
Posted 郑州大学计算机李银霞
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了学生管理系统利用网页较为成熟的优化。。。相关的知识,希望对你有一定的参考价值。
基础的web页面
1 <?xml version="1.0" encoding="ISO-8859-1"?> 2 3 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 6 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 7 version="3.1" 8 metadata-complete="true"> 9 10 <display-name>Welcome to Tomcat</display-name> 11 <description> 12 Welcome to Tomcat 13 </description> 14 <!-- 15 表示系统如果静止30分钟,则服务器分配的sessionID会自动改变。。。 16 --> 17 <session-config> 18 <session-timeout>30</session-timeout> 19 </session-config> 20 <welcome-file-list> 21 <!--<welcome-file>index.html</welcome-file>--> 22 <welcome-file>index.jsp</welcome-file> 23 24 </welcome-file-list> 25 </web-app>
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>Insert title here</title> 8 </head> 9 <frameSet rows="20%,*"> 10 <frame src="title.jsp"/> 11 12 <frameset cols="20%,*"> 13 <frame src="menu.jsp"/> 14 <frame src="main.jsp"/> 15 16 </frameset> 17 18 19 20 21 22 </frameSet> 23 24 </html>
标题栏
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>Insert title here</title> 8 </head> 9 <body> 10 <h1 align="center"> <font size="5" color="#ff0000">欢迎进入学生管理系统</font></h1> 11 </body> 12 </html>
菜单栏
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>Insert title here</title> 8 </head> 9 <body> 10 <ul> 11 <li><a href="stuList.jsp" target="_blank">查看学生信息</a></li> 12 <li><a href="add.jsp" target="_blank">添加学生</a></li> 13 </ul> 14 15 </body> 16 </html>
为了保护学生的信息,首先必须要登录!!
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 <div align="center"> 11 <h1>学生登录</h1> 12 <hr> 13 14 <form action="doLogin.jsp" method="post"> 15 <table> 16 <tr> 17 <td>学号:</td><td><input type="text" name="stuID"></td> 18 <td rowspan="3"><%=request.getAttribute("ErrorMSG")==null?"":request.getAttribute("ErrorMSG") %></td> 19 </tr> 20 <tr> 21 <td>密码:</td><td><input type="password" name="passwd"></td> 22 </tr> 23 <tr> 24 <td><input type="submit" value="登录"></td><td ><input type="reset" value="取消"></td> 25 </tr> 26 27 </table> 28 </form> 29 </div> 30 </body> 31 </html>
检查登录时输入的信息是否正确。
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ page import="com.xt.stuSystem.util.DBUtil" %> 4 <%@ page import="java.sql.*" %> 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>Insert title here</title> 10 </head> 11 <body> 12 <% Connection conn=null; 13 PreparedStatement ps=null; 14 ResultSet rs=null; 15 DBUtil dbu=DBUtil.getDBUtilInstance(); 16 17 request.setCharacterEncoding("UTF-8"); 18 String stuID=request.getParameter("stuID"); 19 String passwd=request.getParameter("passwd"); 20 String sql="select*from student where stuID=? and passwd=password(?)"; 21 22 try{ 23 conn=dbu.getConnection(); 24 ps=conn.prepareStatement(sql); 25 ps.setString(1, stuID); 26 ps.setString(2, passwd); 27 rs=ps.executeQuery(); 28 if(rs.next()){ 29 System.out.println("信息正确,进入首页!!"); 30 request.setAttribute("rightEnter", stuID+" and "+passwd); 31 request.getRequestDispatcher("stuList.jsp").forward(request,response); 32 }else{ 33 34 request.setAttribute("ErrorMSG","学号或者密码错误!!"); 35 request.getRequestDispatcher("login.jsp").forward(request, response); 36 } 37 38 }catch(Exception e){ 39 e.printStackTrace(); 40 System.out.println("有错误"+e); 41 }finally{ 42 dbu.closeResultSet(rs); 43 dbu.closeStatement(ps); 44 dbu.closeConnection(conn); 45 } 46 %> 47 48 49 </body> 50 </html>
学生管理系统有基础的增,删,改,查!!
添加学生信息的网页程序
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>Insert title here</title> 8 </head> 9 <body> 10 11 <div align="center"> 12 <h1><font color="red"><em>添加学生页面</em></font></h1> 13 <hr> 14 <form action="doAdd.jsp" method="get"> 15 <table> 16 <tr> 17 <td>学号:</td><td><input type="text" name="stuID" ></td> 18 </tr> 19 <tr> 20 <td>姓名:</td><td><input type="text" name="stuName" ></td> 21 </tr> 22 <tr> 23 <td>性别:</td><td><input type="radio" name="gender" value="男">男</td> 24 <td><input type="radio" name="gender" value="女">女</td> 25 </tr> 26 <tr> 27 <td>年龄:</td><td><input type="text" name="age"></td> 28 </tr> 29 <tr> 30 <td>分数:</td><td><input type="text" name="score"></td> 31 </tr> 32 <tr> 33 <td>密码:</td><td><input type="password" name="passwd"></td> 34 </tr> 35 <tr> 36 <td colspan="2"><input type="submit" value="提交"></td> 37 <td colspan="2"><input type="reset" value="重置"></td> 38 </tr> 39 40 </table> 41 </form> 42 </div> 43 44 45 </body> 46 </html>
将添加的信息添加到数据库的操作!!
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ page import="com.xt.stuSystem.util.DBUtil" %> 4 <%@ page import="java.sql.*" %> 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>Insert title here</title> 10 </head> 11 <body> 12 <% 13 request.setCharacterEncoding("UTF-8"); 14 String stuID=request.getParameter("stuID"); 15 String stuName=request.getParameter("stuName"); 16 String gender=request.getParameter("gender"); 17 String age=request.getParameter("age"); 18 String score=request.getParameter("score"); 19 String passwd=request.getParameter("passwd"); 20 21 System.out.println(stuID+"-----"+stuName+"------"+gender); 22 System.out.println(age+"-----"+score+"------"+passwd); 23 24 Connection conn=null; 25 PreparedStatement ps=null; 26 ResultSet rs=null; 27 DBUtil dbu=DBUtil.getDBUtilInstance(); 28 String sql="insert into student(stuID,stuName,gender,age,score,passwd) values(?,?,?,?,?,password(?))"; 29 try{ 30 conn=dbu.getConnection(); 31 ps=conn.prepareStatement(sql); 32 ps.setString(1,stuID); 33 ps.setString(2,stuName); 34 ps.setString(3,gender); 35 ps.setInt(4,Integer.parseInt(age.trim())); 36 ps.setDouble(5,Double.parseDouble(score.trim())); 37 ps.setString(6,passwd); 38 if(ps.executeUpdate()>0){ 39 System.out.println("信息已经成功添加!"); 40 request.getRequestDispatcher("index.jsp").forward(request,response); 41 } 42 }catch(Exception e){ 43 e.printStackTrace(); 44 e.getMessage(); 45 e.getStackTrace(); 46 System.out.println("Error:"+e); 47 }finally{ 48 dbu.closeStatement(ps); 49 dbu.closeConnection(conn); 50 } 51 52 %> 53 54 </body> 55 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ page import="com.xt.stuSystem.util.DBUtil" %> 4 <%@ page import="java.sql.*" %> 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>Insert title here</title> 10 </head> 11 <body> 12 <% 13 request.setCharacterEncoding("UTF-8"); 14 String stuID=request.getParameter("stuID"); 15 String stuName=request.getParameter("stuName"); 16 String gender=request.getParameter("gender"); 17 String age=request.getParameter("age"); 18 String score=request.getParameter("score"); 19 String passwd=request.getParameter("passwd"); 20 21 System.out.println(stuID+"-----"+stuName+"------"+gender); 22 System.out.println(age+"-----"+score+"------"+passwd); 23 24 Connection conn=null; 25 PreparedStatement ps=null; 26 ResultSet rs=null; 27 DBUtil dbu=DBUtil.getDBUtilInstance(); 28 String sql="insert into student(stuID,stuName,gender,age,score,passwd) values(?,?,?,?,?,password(?))"; 29 try{ 30 conn=dbu.getConnection(); 31 ps=conn.prepareStatement(sql); 32 ps.setString(1,stuID); 33 ps.setString(2,stuName); 34 ps.setString(3,gender); 35 ps.setInt(4,Integer.parseInt(age.trim())); 36 ps.setDouble(5,Double.parseDouble(score.trim())); 37 ps.setString(6,passwd); 38 if(ps.executeUpdate()>0){ 39 System.out.println("信息已经成功添加!"); 40 request.getRequestDispatcher("index.jsp").forward(request,response); 41 } 42 }catch(Exception e){ 43 e.printStackTrace(); 44 e.getMessage(); 45 e.getStackTrace(); 46 System.out.println("Error:"+e); 47 }finally{ 48 dbu.closeStatement(ps); 49 dbu.closeConnection(conn); 50 } 51 52 %> 53 54 </body> 55 </html>
删除学生的操作!!!
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ page import="com.xt.stuSystem.util.DBUtil" %> 4 <%@ page import="java.sql.*" %> 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>Insert title here</title> 10 </head> 11 <body> 12 <% 13 String stuID=request.getParameter("stuID"); 14 Connection conn=null; 15 Statement stat=null; 16 DBUtil dbu=DBUtil.getDBUtilInstance(); 17 String sql="delete from student where stuID="+stuID; 18 System.out.print(sql); 19 try{ 20 conn=dbu.getConnection(); 21 stat=conn.createStatement(); 22 if(stat.executeUpdate(sql)>0){ 23 System.out.println("成功删除!!"); 24 request.setAttribute("rightEnter", stuID+" !! "); 25 request.getRequestDispatcher("stuList.jsp").forward(request,response); 26 } 27 28 }catch(Exception e){ 29 System.out.println("错误"+e); 30 }finally{ 31 dbu.closeStatement(stat); 32 dbu.closeConnection(conn); 33 } 34 35 %> 36 37 </body> 38 </html>
改正学生的操作!!
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@page import="com.xt.stuSystem.util.DBUtil" %> 4 <%@ page import="java.sql.*" %> 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>Insert title here</title> 10 </head> 11 <body> 12 <% 13 String stuID=request.getParameter("stuID"); 14 Connection conn=null; 15 Statement stat=null; 16 ResultSet rs=null; 17 DBUtil dbu=DBUtil.getDBUtilInstance(); 18 StringBuffer sql=new StringBuffer("select * from student where stuID=‘"); 19 sql.append(stuID).append("‘"); 20 System.out.println(sql); 21 try{ 22 conn =dbu.getConnection(); 23 stat=conn.createStatement(); 24 rs=stat.executeQuery(sql.toString()); 25 26 27 %> 28 29 <h1 align="center"><font color="red"><em>修改页面</em></font></h1> 30 <hr> 31 <form action="doUpdate.jsp" method="post"> 32 33 34 <%while(rs.next()) { 35 36 %> 37 38 <table align="center"> 39 <!-- <input type="hidden" name="stuID1" value="<%=rs.getString(1) %>"> 40 --> 41 <tr> 42 <td>学号:</td><td><input type="text" name="stuID" value="<%=stuID%>" ></td> 43 </tr> 44 <tr> 45 <td>姓名:</td><td><input type="text" name="stuName" value="<%=rs.getString(2)%>"></td> 46 </tr> 47 <tr> 48 <td>性别:</td><td><input type="radio" <%="男".equals(rs.getString(3))?"checked":""%> value="男" name="gender" >男</td> 49 <td><input type="radio" <%="女".equals(rs.getString(3))?"checked":""%> value="女"name="gender" >女</td> 50 </tr> 51 <tr> 52 <td>年龄:</td><td><input type="text" name="age" value="<%=rs.getInt(4)%>"></td> 53 </tr> 54 <tr> 55 <td>分数:</td><td><input type="text" name="score" value="<%=rs.getDouble(5)%>"></td> 56 </tr> 57 <tr> 58 <td>密码:</td><td><input type="password" name="passwd" value="<%=rs.getString(6)%>"></td> 59 </tr> 60 <tr> 61 <td colspan="2"><input type="submit" value="提交"></td> 62 <td colspan="2"><input type="reset" value="重置"></td> 63 </tr> 64 </table> 65 <%} %> 66 </form> 67 <% 68 }catch(Exception e){ 69 e.printStackTrace(); 70 System.out.print("错误"+e); 71 }finally{ 72 dbu.closeResultSet(rs); 73 dbu.closeStatement(stat); 74 dbu.closeConnection(conn); 75 } 76 77 %> 78 </body> 79 </html>
将改正的信息添加到数据库!
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ page import="com.xt.stuSystem.util.DBUtil" %> 4 <%@ page import="java.sql.*" %> 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>Insert title here</title> 10 </head> 11 <body> 12 <% 13 Connection conn=null; 14 PreparedStatement ps=null; 15 DBUtil dbu=DBUtil.getDBUtilInstance(); 16 request.setCharacterEncoding("UTF-8"); 17 String stuID=request.getParameter("stuID"); 18 System.out.println(stuID); 19 String stuName=request.getParameter("stuName"); 20 String gender=request.getParameter("gender"); 21 String age=request.getParameter("age"); 22 String score=request.getParameter("score"); 23 String passwd=request.getParameter("passwd"); 24 try{ 25 System.out.println(stuID+"---"+stuName+"---"+gender); 26 String sql="update student set stuName=?,gender=?,age=?,score=?,passwd=password(?) where stuID=‘"+stuID+"‘"; 27 System.out.print(sql); 28 29 30 conn=dbu.getConnection(); 31 ps=conn.prepareStatement(sql); 32 ps.setString(1,stuName); 33 ps.setString(2,gender); 34 ps.setInt(3, Integer.parseInt(age)); 35 ps.setDouble(4,Double.parseDouble(score)); 36 ps.setString(5,passwd); 37 if(ps.executeUpdate()>0){ 38 System.out.print("信息已经成功改正!!"); 39 request.getRequestDispatcher("stuList.jsp").forward(request,response); 40 41 } 42 43 }catch(Exception e){ 44 e.printStackTrace(); 45 }finally{ 46 dbu.closeStatement(ps); 47 dbu.closeConnection(conn); 48 } 49 %> 50 51 </body> 52 </html>
显示学生信息的操作!
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ page import="com.xt.stuSystem.util.DBUtil" %> 4 <%@ page import="java.sql.*" %> 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>Insert title here</title> 10 </head> 11 <body> 12 <% if(request.getAttribute("rightEnter")==null){ 13 request.getRequestDispatcher("login.jsp").forward(request, response); 14 } 15 16 17 request.setCharacterEncoding("UTF-8"); 18 String stuID1=null; 19 String stuName=null; 20 stuID1=request.getParameter("stuID1"); 21 stuName=request.getParameter("stuName"); 22 Connection conn=null; 23 Statement stat=null; 24 ResultSet rs=null; 25 DBUtil dbu=DBUtil.getDBUtilInstance(); 26 StringBuffer sql=new StringBuffer("select * from student where 1=1 "); 27 if(stuID1!=null&&!"".equals(stuID1)){ 28 sql.append(" and stuID=").append(stuID1.trim()); 29 } 30 if(stuName!=null&&!"".equals(stuName)){ 31 sql.append(" and stuName like ‘%").append(stuName.trim()).append("%‘"); 32 } 33 System.out.println(sql); 34 try{ 35 conn=dbu.getConnection(); 36 stat=conn.createStatement(); 37 rs=stat.executeQuery(sql.toString()); 38 39 %> 40 <div align="center"> 41 <form action="" method="post"> 42 <table> 43 <tr> 44 <td>学号:</td><td><input type="text" name="stuID1" value="<%=stuID1==null?"":stuID1%>"></td> 45 <td>姓名:</td><td><input type="text" name="stuName" value="<%=stuName==null?"":stuName%>"></td> 46 </tr> 47 <tr> 48 <td colspan="2" align="center"><input type="submit" value="查询"></td> 49 <td colspan="2" align="center"><input type="reset" value="取消"></td> 50 51 </tr> 52 </table> 53 <hr> 54 </form> 55 56 57 58 <table border="1px" bordercolor="red" cellpadding="0" cellspacing="0" width="800px" > 59 <tr> 60 <th>学号</th><th>姓名</th><th>性别</th><th>年龄</th><th>成绩</th><th>密码</th><th>操作</th> 61 </tr> 62 <% 63 while(rs.next()){ 64 %> 65 <tr> 66 <td><%=rs.getString(1) %></td><td><%=rs.getString(2) %></td><td><%=rs.getString(3) %></td> 67 <td><%=rs.getInt(4) %></td><td><%=rs.getDouble(5) %></td><td><%=rs.getString(6) %></td> 68 <td><a href="delete.jsp?stuID=<%=rs.getString(1)%>">删除</a> <a href="update.jsp?stuID=<%=rs.getString(1)%>">修改</a></td> 69 </tr> 70 <% 71 } 72 %> 73 </table> 74 </div> 75 76 </body> 77 <% 78 79 }catch(Exception e){ 80 e.printStackTrace(); 81 System.out.println("有错误"+e); 82 }finally{ 83 dbu.closeResultSet(rs); 84 dbu.closeStatement(stat); 85 dbu.closeConnection(conn); 86 } 87 %> 88 </html>
以上是关于学生管理系统利用网页较为成熟的优化。。。的主要内容,如果未能解决你的问题,请参考以下文章