简单的学生信息管理系统

更新时间:2023-08-25 08:20:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

//连接数据库方法类

JDBCConnection.java

packagegj;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.SQLException;

public class JDBCConnection {

String driverName = "com.mysql.jdbc.Driver"; //驱动程序名

String userName = "root"; //数据库用户名

String userPwd = "text"; //密码

String dbName = "user"; //数据库名

String tableName = "user_list3"; //数据表名

String url ="";

public String getDriverName() {

returndriverName;

}

public void setDriverName(String driverName) {

this.driverName = driverName;

}

public String getUserName() {

returnuserName;

}

public void setUserName(String userName) {

http://www.77cn.com.cnerName = userName;

}

public String getUserPwd() {

returnuserPwd;

}

public void setUserPwd(String userPwd) {

http://www.77cn.com.cnerPwd = userPwd;

}

public String getDbName() {

returndbName;

}

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

public void setDbName(String dbName) {

this.dbName = dbName;

}

public String getTableName() {

returntableName;

}

public void setTableName(String tableName) {

this.tableName = tableName;

}

public String getUrl() {

returnurl;

}

public void setUrl(String url) {

this.url = url;

}

//实现数据库连接的方法

public Connection getConnection() throws SQLException,

ClassNotFoundException { //实现数据库连接的方法

String url1="jdbc:mysql://localhost:3306/"+dbName;

String url2 ="?user="+userName+"&password="+userPwd;

String url3="&useUnicode=true&characterEncoding=GB2312";

url =url1+url2+url3;

Class.forName(driverName);

returnDriverManager.getConnection(url);

}

}

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

//用户登录界面

Index.jsp

<head>

{

varuserName=document.forms["form1"].UserName.value;

varpassword=document.forms["form1"].pd.value;

if(userName.length<=0)

{

alert("用户名不能为空!");

}

else if(password<=0)

{

alert("密码不能为空!");

}

else

{

document.forms["form1"].submit();

}

}

</script>

</head>

<title>My JSP 'index.jsp' starting page</title> <script type="text/javascript"> functionvalidate()

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

<br> <br> <div align="left"> <h2> 用户登录 </h2>

<br>

<br>

<form action="CheckShow" name="form1" method="post"> <table width="248" height="106" border="0"> <tr> <td> 用户名: </td> <td> <input type="text" name="UserName" /> </td> </tr> <tr> <td> 密&nbsp;码: </td> <td> <input type="password" name="pd" /> </td> </tr> <tr> <td colspan="2"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input

type="button" value="登录" onclick="validate()" onmousemove="hand">

<a href="register.jsp"><font size="2" face="黑体">注册</font></a>&nbsp;&nbsp;<input type="reset" value="重置"> </td>

</tr> </table> </form> <p><%=request.getAttribute("return")%></p> <p align="left"><% int count = 0; if (application.getAttribute("count") == null) { count += 1;

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

} count = Integer.parseInt(application.getAttribute("count") .toString()); count += 1; application.setAttribute("count", count); } else {

out.print("您是本系统的第"+count+"位访问者!");

%></p>

<p><%=newDate() %></p>

</div>

</body>

</html>

//用户登录后台验证类

CheckLogin.java

packagegj;

importjava.sql.Connection;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.sql.Statement;

public class CheckLogin {

private String name;

private String password;

public String getName() {

return name;

}

public void setName(String name) {

http://www.77cn.com.cn = name;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

publicCheckLogin(String name, String password) {

super();

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

http://www.77cn.com.cn = name;

this.password = password;

}

publicint Check() throws SQLException, ClassNotFoundException {

JDBCConnectionkkk = new JDBCConnection();

Connection con = kkk.getConnection();

Statement statement;

try {

statement = con.createStatement();

String sql = "select * from user_list3 where name='" + name + "'";

ResultSetrs = statement.executeQuery(sql);

ResultSet rs1 = null;

if (!rs.next()) {

return 1;

} else {

String sql1 = "select * from user_list3 where password='"

+ password + "'";

rs1 = statement.executeQuery(sql1);

if (!rs1.next()) {

return 2;

}

}

rs.close();

rs1.close();

statement.close();

con.close();

} catch (Exception e) {

e.printStackTrace();

}

return 3;

}

}

CheckLogin.java 中do post 方法

request.setCharacterEncoding("GB2312");

String name = request.getParameter("UserName"); String pd = request.getParameter("pd");

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

);

try { switch (cl.Check()) { case 1: request.setAttribute("return","用户名不存在!注册?"); request.getRequestDispatcher("index.jsp").forward(request, response); break; request.setAttribute("return","密码不存在!"); case 2: request.getRequestDispatcher("index.jsp").forward(request,respons break; e); case 3: request.getRequestDispatcher("main.jsp").forward(request,response } } // TODO Auto-generated catch block e1.printStackTrace(); // TODO Auto-generated catch block e1.printStackTrace(); } catch (SQLException e1) { } catch (ClassNotFoundException e1) {

//用户类

http://www.77cn.com.cner;

publicclass user {

private String UserName;

private String pd;

public String getUserName() {

}

publicvoidsetUserName(String userName) {

}

public String getPd() {

}

publicvoidsetPd(String pd) {

this.pd = pd; returnpd; UserName = userName; returnUserName;

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

public user(String userName, String pd) {

}

}

super(); UserName = userName; this.pd = pd;

//用户注册界面

Register.Jsp

<html>

{

varuserName=document.forms["form2"].name.value;

varpassword=document.forms["form2"].password.value;

varrepassword=document.forms["form2"].repassword.value;

if(userName.length<=0)

{

alert("用户名不能为空!");

}

else if

(password<=0) <head> <title>My JSP 'register.jsp' starting page</title> <script type="text/javascript"> functionfdate()

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

alert("密码不能为空!");

}

else if(password!=repassword)

{

alert("两次输入密码不一致!");

}

else

{

document.forms["form2"].submit();

}

}

</script>

<form action="Register" name="form2" method="post"> <table width="242" height="133" border="0"> <tr> <td> 用户名: </td> <td> <input type="text" name="name" /> </td> <body bgcolor="#9999FF"> <h2>用户注册<br> </h2> </head> </tr> <tr> <td> 密&nbsp;&nbsp;码: </td> <td> <input type="password" name="password" /> </td> </tr> <tr> <td> 再次输入: </td> <td> <input type="password" name="repassword" />

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

</tr> <tr> <td colspan="2"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="button" value="注册"

onclick="fdate()"/>

&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="重置" /> </td> </tr> </table> </form> <p><%=request.getAttribute("success") %></p> <a href="index.jsp">返回登录界面</a> </body>

</html>

//用户注册写入数据库servlet

Register.jsp

package servlet;

importgj.JDBCConnection;

importgj.getSQL;

importjava.io.IOException;

importjava.sql.SQLException;

importjavax.servlet.ServletException;

importjavax.servlet.http.HttpServlet;

importjavax.servlet.http.HttpServletRequest;

importjavax.servlet.http.HttpServletResponse;

publicclass register extendsHttpServlet {

publicvoiddoGet(HttpServletRequest request, HttpServletResponse response) publicvoid destroy() { } super.destroy(); // Just puts "destroy" string in log // Put your code here public register() { } super();

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

} doPost(request, response); publicvoiddoPost(HttpServletRequest request, HttpServletResponse } throwsServletException, IOException { response) request.setCharacterEncoding("GB2312"); String name = request.getParameter("name"); String password = request.getParameter("password"); JDBCConnection j = newJDBCConnection(); try { } getSQLgl = newgetSQL(name, password); try { } request.setAttribute("success", "注册成功!"); request.getRequestDispatcher("register.jsp").forward(request, gl.getValue(); // TODO Auto-generated catch block e.printStackTrace(); // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { j.getConnection(); // TODO Auto-generated catch block e.printStackTrace(); // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { } catch (ClassNotFoundException e) { } catch (SQLException e) { response);

//向数据库中添加数据类

packagegj;

importjava.sql.Connection;

importjava.sql.SQLException;

importjava.sql.Statement;

publicclassgetSQL {

private String name; private String password;

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

} publicvoidgetValue() throwsClassNotFoundException, SQLException { super(); http://www.77cn.com.cn = name; this.password = password;

JDBCConnectionkkk=newJDBCConnection();

Connection con=kkk. getConnection() ;

Statement statement = con.createStatement();

String sql ="insert into user_list3

values('"+name+"','"+password+"')";

statement. executeUpdate(sql);

statement.close();

con.close();

}

}

//用户查询界面

Query.jsp

<html>

<body background="img/5.jpg"> <br> <br> <br> <br><br> <br>

<head> <title>My JSP 'success.jsp' starting page</title> </head>

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

数据查询 </p> <form action="query.jsp" method="post" name="form3"> <p align="center"> 按用户查询: <input type="text" name="StuName" /> </p> <p align=center> <input type="submit" value="查询"> </p> </form> <p align="center"> 查询内容如下: </p> <% %> <center> <table border="2" bgcolor="ccceee" width="600"> <trbgcolor="CCCCCC" align="center"> <% %> <tralign="center"> <% <td><%=stu[i].getNumber()%></td> <td><%=stu[i].getName()%></td> <td><%=stu[i].getEmail()%></td> for (inti = 0; i<stu.length; ++i) { <td> 编号 </td> <td> 名字 </td> <td> email </td> request.setCharacterEncoding("GB2312"); String name = request.getParameter("StuName"); String sql = "select * from student where name='" + name + "'"; query q = new query(); studentstu[] = q.QueryStu(sql); </tr> </tr>

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

%> </table> <p> 共有 <font color="red"><%=stu.length%></font>条记录,查询结果如上表所示!

</p>

</center> </body>

</html>

//学生类

Student.java

publicclass student {

private String number; private String name; private String email; public String getNumber() { } publicvoidsetNumber(String number) { } public String getName() { } publicvoidsetName(String name) { } public String getEmail() { } publicvoidsetEmail(String email) { } public student(String number, String name, String email) { } publicvoidgetValue() throwsClassNotFoundException, SQLException super(); this.number = number; http://www.77cn.com.cn = name; this.email = email; this.email = email; returnemail; http://www.77cn.com.cn = name; returnname; this.number = number; returnnumber;

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

{

JDBCConnectionkkk=newJDBCConnection();

kkk.setTableName("student");

Connection con=kkk. getConnection() ;

Statement statement = con.createStatement();

String sql ="insert into student

values('"+number+"','"+name+"','"+email+"')";

statement. executeUpdate(sql);

statement.close();

con.close();

}

}

//学生信息查询类

Query.java

http://www.77cn.com.cner;

importgj.JDBCConnection;

importjava.sql.Connection;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.sql.Statement;

public class query {

public query() {

}

public user[] Query(String sql) throws SQLException, ClassNotFoundException { JDBCConnectionkkk = new JDBCConnection();

Connection con = kkk.getConnection();

Statement statement = con.createStatement();

ResultSetrs = statement.executeQuery(sql);

http://www.77cn.com.cnst();

user[] user2 = new user[rs.getRow()];

rs.beforeFirst();

inti = 0;

while (rs.next()) {

user2[i] = new user(rs.getString("name"), rs.getString("password")); i = i + 1;

}

rs.close();

statement.close();

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

con.close();

return user2;

}

//学生信息查询

public student[] QueryStu(String sql) throws SQLException, ClassNotFoundException {

JDBCConnectionkkk = new JDBCConnection();

kkk.setTableName("student");

Connection con = kkk.getConnection();

Statement statement = con.createStatement();

ResultSet rs1 = statement.executeQuery(sql);

http://www.77cn.com.cnst();

student[] stu=new student[rs1.getRow()];

rs1.beforeFirst();

inti=0;

while(rs1.next())

{

stu[i]=new

student(rs1.getString("number"),rs1.getString("name"),rs1.getString("email")); i+=1;

}

rs1.close();

statement.close();

con.close();

returnstu;

}

}

//数据添加类

Insert.jsp

<html>

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

{ <title>My JSP 'insert.jsp' starting page</title> <script type="text/javascript"> functionvalidate2()

varNumber=document.forms["form4"].number.value;

varName=document.forms["form4"].name.value;

varEmail=document.forms["form4"].email.value;

if(Number.length<=0)

{

alert("学号不能为空!");

}

else if(Name<=0)

{

alert("名字不能为空!");

}

else if(Email<=0)

{

alert("email不能为空!")

}

else

{

document.forms["form4"].submit();

}

}

</script>

<body background="img/5.jpg"> <br> <br> <center> <h3>学生信息添加</h3> <form action="Insert" method="post" name="form4"> <table width="228" height="112"> <tr> <td> 学号 </td> <td> <input type="text" name="number" /> </head>

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

</tr> <tr> <td> 姓名 </td> <td> <input type="text" name="name" /> </td> </tr> <tr> <td> email </td> <td> <input type="text" name="email" /> </td> </tr> </table>

<p><input type="button" value="提交"

onClick="validate2()"/>&nbsp;&nbsp;

<input type="reset" value="取消"/> </p> </form> <%=request.getAttribute("ok") %> </center> </body>

</html>

//insert.java servlet do post()

publicvoiddoPost(HttpServletRequest request, HttpServletResponse response)

throwsServletException, IOException { request.setCharacterEncoding("GB2312"); String number=request.getParameter("number"); String name=request.getParameter("name"); String email=request.getParameter("email"); studentst=new student(number,name,email); try { st.getValue(); // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) {

jsp中简单的学生管理系统,可以基本实现对数据库的增删查改

} request.setAttribute("ok","添加成功!"); // TODO Auto-generated catch block e.printStackTrace(); request.getRequestDispatcher("insert.jsp").forward(request,response); }

//数据修改

Update.jsp

<html>

<body background="img/5.jpg"> <center> <br> <br> <h2> 请选择要修改的学生 </h2> <br> <br> <% %>

String sql = "select * from student"; query q = new query(); studentstu[] = q.QueryStu(sql); <head> <title>My JSP 'update.jsp' starting page</title> </head>

本文来源:https://www.bwwdw.com/article/vjqi.html

Top