简单的学生信息管理系统
更新时间: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> 密 码: </td> <td> <input type="password" name="pd" /> </td> </tr> <tr> <td colspan="2"> <input
type="button" value="登录" onclick="validate()" onmousemove="hand">
<a href="register.jsp"><font size="2" face="黑体">注册</font></a> <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> 密 码: </td> <td> <input type="password" name="password" /> </td> </tr> <tr> <td> 再次输入: </td> <td> <input type="password" name="repassword" />
jsp中简单的学生管理系统,可以基本实现对数据库的增删查改
</tr> <tr> <td colspan="2"> <input type="button" value="注册"
onclick="fdate()"/>
<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()"/>
<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>
正在阅读:
简单的学生信息管理系统08-25
中国银监会关于加强2012年地方政府融资平台贷款风险监管的指导意04-12
9月党员思想汇报3篇(最新篇)04-15
于冬云—沙尘天气教学设计105-31
质子泵抑制剂 合理用药评价细则07-02
总结对独立性威胁的各种情形09-10
企业技术研发中心项目管理制度11-14
四川省乐山市2013届高三第二次诊断性考试--数学(文)05-27
电路分析与应用练习题(答案)11-17
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 管理系统
- 简单
- 学生
- 信息
- C语言常用库函数
- 2018_2019学年九年级语文上册第四单元15我的叔叔于勒练习新人教版Word版含答案
- 财务部各岗位职责
- 运筹学应用实务--露天矿生产的车辆安排
- 马房小学党建工作制度汇编
- 摄影作品分析
- 住宅楼(混合)施工组织设计
- 新华教育高中部数学同步人教A版必修五第三章不等式-一元二次不等式及其解法基础训练
- 2015-2022年中国造纸行业分析及发展策略研究报告
- 北京光环新网酒仙桥IDC数据中心机房 基础设施和配套条件介绍(最新)
- 职业技能实训平台个人与团队管理
- 学校安全工作述职报告
- 科学道德和学风建设心得-
- 一根回形针换来一栋房
- 国税局实习报告
- 工作流技术在高校教务管理系统中的研究与应用
- 【优化课堂】高二历史人教版必修3层级作业:第2课 “罢黜百家独尊儒术” Word版含解析
- 20111027最新混凝土强度自动统计评定表(根据GB/T50107-2010 溷凝土强度检验评定标准)
- 2021年空姐空少英语面试自我介绍
- 建设工程竣工验收监理评估报告表格大全