学生管理系统(JSP版)(共29页).doc
精选优质文档-倾情为你奉上学生管理系统(JSP版)登录界面:<% page language="java" contentType="text/html; charset=gb2312"pageEncoding="GB2312"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Language" content="zh-cn"><title>登录</title><!- javaScript函数 validateLogin(),用来验证是否填写了用户名和密码:-><script language="JavaScript"><!- function validateLogin() var strUserName = document. frmLogin. StrName.value; var strPassword = document. frmLogin. StrPassword.value; if (strUserName ="") alert("请您输入用户名!"); strUserName.focus(); return false; if (strPassword ="") alert("请输入密码!"); strPassword.focus(); return false; -></script><style type="text/css"><!-body background-image: url(login.JPG);background-repeat: repeat;-></style></head><body bgcolor=cyan><p><img src="Logo.jpg" width="1228" height="193"></p><p> </p><form method="post" name="frmLogin" action="Judge.jsp"onSubmit="javaScript: return validateLogin();"><h1 align=center >学生管理系统</h1><div align="center"><br> <br> <table align="center" bgColor="#CCCCCC" border="1" cellPadding="1"cellSpacing="1" width="300"> <tr> <td align="center" height="47" width="94">用户名:</td> <td height="47" width="172" align="center"> <input name="StrName" type="text" > </td> </tr> <tr> <td align="center" height="47" width="94">密 码:</td> <td height="47" width="172" align="center"> <input name="StrPassword" type="password" ></td> </tr> <tr> <td align="center" height="47" width="94"></td> <td height="47" width="172"><input name="Submit" type="submit"value="提 交"> <input name="Reset" type="reset"value="重 置"></td> </tr> </table> </div></form></body></html>用户验证:<% page contentType="text/html;charset=GB2312" %><% page import="java.sql.*" %> <%! public String getString(String str) String s = str;try byte bb = s.getBytes("GB2312");s = new String(bb);catch (Exception e) return s; %> <% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection conn; Statement stmt; ResultSet rs; String uri = "jdbc:microsoft:sqlserver:/localhost:1433;DatabaseName=stuMan" String user = "sa" String password = "sa" conn = DriverManager.getConnection(uri,user,password); stmt = conn.createStatement(); String strUser = request.getParameter("StrName"); String strPwd = request.getParameter("StrPassword"); String condition = "select * from users where uno='"+strUser+"'and upass='"+ strPwd +"'" rs = stmt.executeQuery(condition); if(rs.next() Integer s3 = rs.getInt(3);if(s3=1) response.sendRedirect("StuInfo.jsp");if(s3=0) session.setAttribute("StrName",getString(strUser);response.sendRedirect("Indiv.jsp"); else response.sendRedirect("Login.jsp"); rs.close(); stmt.close(); conn.close(); %><html> <head><title>Judge.jsp</title> </head> <body bgcolor=cyan> </body></html>跳转界面1:<% page language="java" import="java.util.*" pageEncoding="GB2312"%><% page import="myBean.Students" %><jsp:useBean id="student1" class="myBean.Students" scope="request"></jsp:useBean><html> <head> <title>学生信息</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css"><!-body background-image: url(StuInfo.jpg);background-repeat: repeat;-></style></head> <body bgcolor=cyan> <h4 align="center">所有学生信息表 </h4><br> <jsp:getProperty name="student1" property="queryResult" /> </body></html>后台代码:package myBean;import java.sql.*;public class Students StringBuffer queryResult;public Students() queryResult = new StringBuffer();try Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");catch (Exception e) public String handleString(String s) String str = s;try byte bb = str.getBytes("GB2312");str = new String(bb);return str;catch (Exception e) return str;public StringBuffer getQueryResult() Connection conn;Statement stmt;ResultSet rs;String uri = "jdbc:microsoft:sqlserver:/localhost:1433;DatabaseName=stuMan"String user = "sa"String password = "sa"try queryResult.append("<table align=center border=1 bgcolor=#FFFFFF>");conn = DriverManager.getConnection(uri, user, password);stmt = conn.createStatement();rs = stmt.executeQuery("select * from student");queryResult.append("<tr align=center>");queryResult.append("<th align=center width=50>学号</th>");queryResult.append("<th align=center width=50>姓名</th>");queryResult.append("<th align=center width=50>性别</th>");queryResult.append("<th align=center width=50>班级</th>");queryResult.append("<th align=center width=100>地址</th>");queryResult.append("<th align=center width=80>出生日期</th>");queryResult.append("<th align=center width=100>联系方式</th>");queryResult.append("<th align=center width=100>电子邮件</th>");queryResult.append("<th align=center width=80>操作列</th>");queryResult.append("</tr>");while(rs.next() queryResult.append("<tr align=center>");for(int k=1;k<=8;k+)queryResult.append("<td align=center>" + handleString(rs.getString(k) + "</td>");queryResult.append("<td align=center><a href=Update.jsp?sno="+ handleString(rs.getString(1)+ ">修改</a>|<a href=Delete.jsp?sno="+ handleString(rs.getString(1)+ ">删除</a></td>");queryResult.append("</tr>");queryResult.append("</table>");queryResult.append("<br>");queryResult.append("<div align='center' >");queryResult.append("<a href='Addshow.jsp'>增加</a>");queryResult.append(" ");queryResult.append(" ");queryResult.append(" ");queryResult.append(" ");queryResult.append("<a href='Login.jsp'>返回登录界面</a>");queryResult.append("</div>");conn.close();catch (SQLException e) e.printStackTrace();return queryResult;跳转界面2:<% page language="java" import="java.util.*" pageEncoding="GB2312"%><% page import="java.sql.*" %><%!public String getString(String s) String str = s;try byte bb = str.getBytes("GB2312");str = new String(bb);return str;catch (Exception e) return str;%><html> <head> <title>学生信息</title> </head> <body bgcolor=cyan> <h4 align="center">学生个人信息表 </h4><br> <% String number = (String)session.getAttribute("StrName"); String condition = "select * from student where sno = '"+number +"'" Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection conn ;Statement stmt;ResultSet rs;String uri = "jdbc:microsoft:sqlserver:/localhost:1433;DatabaseName=stuMan"String user = "sa"String password = "sa"try out.print("<table align='center' border=1 bgcolor=#FFFFFF>");conn = DriverManager.getConnection(uri, user, password);stmt = conn.createStatement();rs = stmt.executeQuery(condition);out.print("<tr align='center'>");out.print("<th align='center' width=50>学号</th>");out.print("<th align='center' width=50>姓名</th>");out.print("<th align='center' width=50>性别</th>");out.print("<th align='center' width=50>班级</th>");out.print("<th align='center' width=100>地址</th>");out.print("<th align='center' width=80>出生日期</th>");out.print("<th align='center' width=100>联系方式</th>");out.print("<th align='center' width=100>电子邮件</th>");out.print("<th align='center' width=80>操作列</th>");out.print("</tr>");while(rs.next() out.print("<tr align=center>");for(int k=1;k<=8;k+)out.print("<td align='center'>" + getString(rs.getString(k) + "</td>");out.print("<td align=center><a href=IndivUpdate.jsp?sno="+ getString(rs.getString(1)+ ">修改</a></td>");out.print("</tr>");out.print("</table>");out.print("<br>");out.print("<div align='center' ><a href='Login.jsp'"+">返回登录界面</a></div>");conn.close();catch (SQLException e) e.printStackTrace(); %> </body></html>添加界面:<% page language="java" import="java.util.*" pageEncoding="GB2312"%><% page import="myBean.Students" %><% page import="myBean.AddBean" %><jsp:useBean id="query1" class="myBean.Students" scope="request" ></jsp:useBean><jsp:useBean id="student1" class="myBean.AddBean" scope="request" ></jsp:useBean><html> <head><title>添加学生信息界面</title></head> <body bgcolor=cyan> <h2 align="center">添加学生信息界面</h2> <hr size="4" width=80%> <br> <form name="form1" method="post" action=""> <div align="center"> <table bgcolor=#FFFFFF width="280" height="280" border="1" align="center"> <tr> <td width="60"><div align="center">学号</div></td> <td width="189"><div align="center"> <input type="text" name="strsno"> </div></td> </tr> <tr> <td><div align="center">姓名</div></td> <td><div align="center"> <input type="text" name="sname"> </div></td> </tr> <tr> <td><div align="center">性别</div></td> <td><div align="center"> <input type="radio" name="sex" value="男"> 男 <input type="radio" name="sex" value="女"> 女</div></td> </tr> <tr> <td><div align="center">班级</div></td> <td><div align="center"> <input type="text" name="className"> </div></td> </tr> <tr> <td><div align="center">地址</div></td> <td><div align="center"> <input type="text" name="address"> </div></td> </tr> <tr> <td><div align="center">出生日期</div></td> <td><div align="center"> <input type="text" name="birthday"> </div></td> </tr> <tr> <td><div align="center">联系方式</div></td> <td><div align="center"> <input type="text" name="phone"> </div></td> </tr> <tr> <td><div align="center">电子邮件</div></td> <td><div align="center"> <input type="text" name="email"> </div></td> </tr> </table> <p><input type="submit" name="tijiao" value="提交"> <input type="reset" name="chongzhi" value="重置"> <p><a href="StuInfo.jsp">返回</a></p> </div> </form> <br> <jsp:setProperty name="student1" property="*"/> <jsp:getProperty name="student1" property="addMessage" /> </body></html>后台代码:package myBean;import java.sql.*;public class AddBean String strsno = ""String sname = ""String sex = ""String className = ""String address = ""String birthday = ""String phone = ""String email = ""String addMessage = ""public AddBean() try Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");catch (Exception e) public String getString(String str) String s = str;try byte bb = s.getBytes("GB2312");s = new String(bb);catch (Exception e) return s;public String getStrsno() return strsno;public void setStrsno(String strsno) try strsno = new String(strsno.getBytes("ISO-8859-1"),"Gb2312");catch (Exception e) e.printStackTrace();this.strsno = strsno.trim();public String getSname() return sname;public void setSname(String sname) try sname = new String(sname.getBytes("ISO-8859-1"),"Gb2312");catch (Exception e) e.printStackTrace();this.sname = sname.trim();public String getSex() return sex;public void setSex(String sex) try sex = new String(sex.getBytes("ISO-8859-1"),"Gb2312");catch (Exception e) e.printStackTrace();this.sex = sex.trim();public String getClassName() return className;public void setClassName(String className) try className = new String(className.getBytes("ISO-8859-1"),"Gb2312");catch (Exception e) e.printStackTrace();this.className = className.trim();public String getAddress() return address;public void setAddress(String address) try address = new String(address.getBytes("ISO-8859-1"),"Gb2312");catch (Exception e) e.printStackTrace();this.address = address.trim();public String getBirthday() return birthday;public void setBirthday(String birthday) try birthday = new String(birthday.getBytes("ISO-8859-1"),"Gb2312");catch (Exception e) e.printStackTrace();this.birthday = birthday.trim();public String getPhone() return phone;public void setPhone(String phone) try phone = new String(phone.getBytes("ISO-8859-1"),"Gb2312");catch (Exception e) e.printStackTrace();this.phone = phone.trim();public String getEmail() return email;public void setEmail(String email) try email = new String(email.getBytes("ISO-8859-1"),"Gb2312");catch (Exception e) e.printStackTrace();this.email = email.trim();public String getAddMessage() if(strsno.equals("")addMessage = "没有插入记录"elseString condition = "insert student values(?,?,?,?,?,?,?,?)"/String condition = "insert student values('"+strsno+"','"+sname+"','"+sex+"','"+className+"','"+address+"','"+birthday+"','"+phone+"','"+email+"')"String uri = "jdbc:microsoft:sqlserver:/localhost:1433;DatabaseName=stuMan"String user = "sa"String password = "sa"Connection conn;PreparedStatement stmt;try conn = DriverManager.getConnection(uri, user, password);stmt = conn.prepareStatement(condition);stmt.setString(1, strsno);stmt.setString(2, sname);stmt.setString(3, sex);stmt.setString(4, className);stmt.setString(5, address);stmt.setString(6, birthday);stmt.setString(7, phone);stmt.setString(8, email);int m = stmt.executeUpdate();if(m!=0)addMessage = "对表中添加" + m + "记录"elseaddMessage = "添加记录失败!"stmt.close();conn.close();