java web学生信息管理系统.doc
Web程序设计 学生信息管理系统 姓名:鲁超、刘千飞、肖伟超万联播、张明明、白浩班级: 软件0901 时间:2011/12/22 一、实验目的 熟练运用web开发技术设计完成一个学生信息管理系统。二、实验原理功能要求:基于B/S架构实现学生信息的增删改查展示功能,实现完整的应用构建和界面设计。技术要求:基于mysql或mssqlserver数据库,以Tomcat为应用服务器,可使用Jsp+Servelt+Javabean完成,鼓励使用struts,Hibernate框架完成设计。三、实验分组成员姓名成员学号负责内容鲁超200907040101删除模块刘千飞200907040102登陆页面及参与总体内容设计肖伟超200907040103修改模块万联播200907040104查询模块张明明200907040105分页及参与总体内容的设计白浩200907040107增加模块四、实验内容登陆主页源代码:login.html:<!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>登陆模块</title></head><body bgcolor=lightblue bgcolor="FFFFFF"><h1 align="center"><b>欢迎登陆学生信息管理系统</b></h1><hr><form action="forward.jsp" method="post"><p></p><table width="52%" border="2" align="center"><tr bgcolor="#FFFFCC"><td align="center" width="43%"><div align="center">用户名:</div></td><td width="57%"><div align="left"><input type="text" name="username"></div></td></tr><tr bgcolor="#CCFF99"><td align="center" width="43%"><div align="center">密码:</div></td><td width="57"><div align="left"><input type="password" name="password"></div></td></tr></table><p align="center"><input type="reset" name="Reset" value="重置"><input type="submit" name="Submit2" value="提交"></p></form></body></html>forward.jsp:<% page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%><!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>login forward</title></head><body bgcolor=lightblue><%String username=null;String password=null;request.setCharacterEncoding("gb2312");response.setContentType("text/html;charset=gb2312");username=request.getParameter("username");password=request.getParameter("password");if(!username.equals("")&&!password.equals("")%><jsp:forward page="login_ok.jsp"><jsp:param name="username" value='<%=username%>'/><jsp:param name="username" value='<%=password%>'/></jsp:forward><%else%><jsp:forward page="error.jsp"><jsp:param name="username" value='<%=username%>'/><jsp:param name="username" value='<%=password%>'/></jsp:forward><%></body></html>login_ok.jsp:<% page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%><!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>Insert title here</title><style type="text/css">inputcolor:red;font-size:12pt;</style></head><body bgcolor=lightblue><center><h1>欢迎您使用学生管理系统</h1></center><hr><%String username=null;String password=null;request.setCharacterEncoding("gb2312");response.setContentType("text/html;charset=gb2312");username=request.getParameter("username");password=request.getParameter("password");out.println("登陆成功,用户名<font color='red'>"+username+"</font>,");out.println("密码<font color='red'>"+password+"</font>");%><br><p align="center">请选择您要进行的操作:<form action="p_cha.html" method="post"><input type="submit" name="cha" value="查 询"> </form><form action="p_shan.html" method="post"><input type="submit" name="shan" value="删 除"> </form><form action="p_gai.html" method="post"><input type="submit" name="gai" value="修 改"> </form><form action="p_zeng.html" method="post"><input type="submit" name="zeng" value="增 加"> </form></body></html>error.jsp:<% page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%><!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>Error</title></head><body bgcolor=lightblue><center><h1>欢迎您使用学生管理系统</h1></center><%String username=null;String password=null;request.setCharacterEncoding("gb2312");response.setContentType("text/html;charset=gb2312");username=request.getParameter("username");password=request.getParameter("password");out.println("您输入的用户名<font color='red'>"+username+"</font>,");out.println("和密码<font color='red'>"+password+"</font>有一项为空,请重新输入:");%><a href="login.html">-返回重新登陆-</a></body></html>学生信息增加模块:p_zeng.html:<% page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%><!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>Insert title here</title><style type="text/css">inputcolor:red;font-size:12pt;</style></head><body bgcolor=lightblue><center><h1>欢迎您使用学生管理系统</h1></center><hr><%String username=null;String password=null;request.setCharacterEncoding("gb2312");response.setContentType("text/html;charset=gb2312");username=request.getParameter("username");password=request.getParameter("password");out.println("登陆成功,用户名<font color='red'>"+username+"</font>,");out.println("密码<font color='red'>"+password+"</font>");%><br><p align="center">请选择您要进行的操作:<form action="p_cha.html" method="post"><input type="submit" name="cha" value="查 询"> </form><form action="p_shan.html" method="post"><input type="submit" name="shan" value="删 除"> </form><form action="p_gai.html" method="post"><input type="submit" name="gai" value="修 改"> </form><form action="p_zeng.html" method="post"><input type="submit" name="zeng" value="增 加"> </form></body></html>zeng.jsp:<% page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312" import="java.sql.*"%><!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>call stored procedure</title></head><body bgcolor=lightblue> <% int PAGESIZE=3; int pageCount=0; int curPage=1; java.sql.Connection conn=null; PreparedStatement pstmt=null; Statement stmt=null; ResultSet rs=null; String cloStr="sno","sname","cclass","sex","age","nation","clname","place" String showStr="学生编号","学生姓名","所在年级","性别","年龄","民族","专业","住址"String sno,sname,cclass,sex,age,nation,clname,place; String strURL="jdbc:mysql:/localhost/test" String strDBUser="root" String strDBPwd="123" try Class.forName("com.mysql.jdbc.Driver"); conn=java.sql.DriverManager.getConnection(strURL,strDBUser,strDBPwd); catch(ClassNotFoundException e) e.printStackTrace(); out.println("您输入的信息有误,请查证后再重新输入!"); catch(Exception ex) ex.printStackTrace(); out.println("您输入的信息有误,请查证后再重新输入!"); try sno=request.getParameter("sno"); byte no=sno.getBytes("ISO-8859-1"); sno=new String(no); sname=request.getParameter("sname"); byte name=sname.getBytes("ISO-8859-1"); sname=new String(name,"gb2312"); cclass=request.getParameter("cclass"); byte clss=cclass.getBytes("ISO-8859-1"); cclass=new String(clss,"gb2312"); sex=request.getParameter("sex"); byte ex=sex.getBytes("ISO-8859-1"); sex=new String(ex,"gb2312"); age=request.getParameter("age"); byte ge=age.getBytes("ISO-8859-1"); age=new String(ge); nation=request.getParameter("nation"); byte tion=nation.getBytes("ISO-8859-1"); nation=new String(tion,"gb2312"); clname=request.getParameter("clname"); byte cname=clname.getBytes("ISO-8859-1"); clname=new String(cname,"gb2312"); place=request.getParameter("place"); byte lace=place.getBytes("ISO-8859-1"); place=new String(lace,"gb2312"); String sqlll="insert into S(sno,sname,cclass,sex,age,nation,clname,place) values('"+sno+"','"+sname+"','"+cclass+"','"+sex+"','"+age+"','"+nation+"','"+clname+"','"+place+"')"pstmt=conn.prepareStatement(sqlll);int count3=pstmt.executeUpdate();/插入 String sqllll="select * from S" stmt=conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY); rs=stmt.executeQuery(sqllll); rs.last();int size=rs.getRow();pageCount=(size%PAGESIZE=0)?(size/PAGESIZE):(size/PAGESIZE+1); catch(Exception ex) ex.printStackTrace(); out.println("您输入的信息有误,请查证后再重新输入!"); /获取想要显示的页数: String integer=request.getParameter("curPage"); if(integer=null) integer="1" try curPage=Integer.parseInt(integer); catch(NumberFormatException e) curPage=1; if(curPage<=1) curPage=1; if(curPage>=pageCount) curPage=pageCount; /如果要显示第curPage页,那么游标应移到posion的值是: int posion=(curPage-1)*PAGESIZE+1; rs.absolute(posion); / 设置游标的位置%><br><table border=1 cellspacing=0 width='100%' class=listFram id="maintable"><tr><%for(int i=0;i<showStr.length;i+)out.println("<td height=5>");out.println("<div align='center'>"+showStri+"</div></td>");%></tr><%int count=0;do if(count>=PAGESIZE)break; out.println("<tr>");for(int i=0;i<cloStr.length;i+)out.println("<td height=5>");out.println("<div align='center'>"+rs.getString(cloStri)+"</div></td>");out.println("</tr>");count+;while(rs.next();%></table><a href = "cha.jsp?curPage=1" >首页</a> <a href = "cha.jsp?curPage=<%=curPage-1%>" >上一页</a> <a href = "cha.jsp?curPage=<%=curPage+1%>" >下一页</a> <a href = "cha.jsp?curPage=<%=pageCount%>" >尾页</a> 第<%=curPage%>页/共<%=pageCount%>页 <FORM action="" method=get >输入页码数<Input Type=text name=curPage size=4> <Input Type=submit name=g value="跳转"> </FORM> </body></html>学生信息删除模块:p_shan.html:<!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>Insert title here</title><style type="text/css">h3color:red;</style></head><body bgcolor=lightblue><center><h1>欢迎您使用学生管理系统</h1></center><p align="center"><hr><div align="right"><a href="login_ok.jsp">返回首页</a></div><h3>删 除 操 作</h3><table align="center"><tr><td>请输入学生学号:<form target="mainFrame" action="shan_xuehao.jsp" method="post" ><input type="text" name="sno" size=20><input type="submit" name="su" value="按学号删除"></form></td><td>请输入学生姓名:<form target="mainFrame" action="shan_xingming.jsp" method="post" ><input type="text" name="sname" size=20><input type="submit" name="su" value="按姓名删除"></form></td></tr><tr><td>请输入学生性别:<form target="mainFrame" action="shan_xingbie.jsp" method="post" ><input type="text" name="sex" size=20><input type="submit" name="su" value="按性别删除"></form></td><td>请输入学生住址:<form target="mainFrame" action="shan_dizhi.jsp" method="post" ><input type="text" name="place" size=20><input type="submit" name="su" value="按地址删除"></form></td></tr></table><p align="center"><iframe width=700 height=700 name="mainFrame" frameborder="no"></iframe></body></html>按学号删除: Shan_xuehao.jsp:<% page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312" import="java.sql.*"%><!DOCTYPE html PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>call stored procedure</title></head><body bgcolor=lightblue> <% int PAGESIZE=3; int pageCount=0; int curPage=1; java.sql.Connection conn=null; PreparedStatement pstmt=null; Statement stmt=null; ResultSet rs=null; String cloStr="sno","sname","cclass","sex","age","nation","clname","place" String showStr="学生编号","学生姓名","所在年级","性别","年龄","民族","专业","住址" String sno; if(conn=null) String strURL="jdbc:mysql:/localhost/test" String strDBUser="root" String strDBPwd="123" try Class.forName("com.mysql.jdbc.Driver"); out.println("连接数据库成功."); conn=java.sql.DriverManager.getConnection(strURL,strDBUser,strDBPwd); catch(ClassNotFoundException e) e.printStackTrace(); out.println("ClassNotFoundException111"); catch(Exception ex) ex.printStackTrace(); out.println("Exception11"); trysno=request.getParameter("sno"); byte no=sno.getBytes("ISO-8859-1"); sno=new String(no);String sql="delete from S where sno="+sno;pstmt=conn.prepareStatement(sql);int count=pstmt.executeUpdate();/删除String sqllll="select * from S"stmt=conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);rs=stmt.executeQuery(sqllll);rs.last();int size=rs.getRow();pageCount=(size%PAGESIZE=0)?(size/PAGESIZE):(size/PAGESIZE+1);catch(Exception ex) ex.printStackTrace(); out.println("您输入的信息有误,请查证后再重新输入!"); /获取想要显示的页数: String integer=request.getParameter("curPage"); if(integer=null) integer="1" try curPage=Integer.parseInt(integer); catch(NumberFormatException e) curPage=1; if(curPage<=1) curPage=1; if(curPage>=pageCount) curPage=pageCount; /如果要显示第curPage页,那么游标应移到posion的值是: int posion=(curPage-1)*PAGESIZE+1; rs.absolute(posion); / 设置游标的位置%><br><table border=1 cellspacing=0 width='100%' class=listFram id="maintable"><tr><%for(int i=0;i<showStr.length;i+)out.println("<td height=5>");out.println("<div align='center'>"+showStri+"</div></td>");%></tr><%int count=0;do if(count>=PAGESIZE)break; out.println("<tr>");for(int i=0;i<cloStr.length;i+)out.println("<td height=5>");out.println("<div align='center'>"+rs.getString(cloStri)+"</div></td>");out.println("</tr>");count+;while(rs.next();%></table><a href = "