所用工具:myeclipse、dreamweaver CS6、mysql-front、tomcat、mysql-connector-java-5.1.12-bin

功能:用户通过输入密码登录进系统,可以对学生信息进行添加、删除、修改基本信息和密码以及查询等操作。

 

所有需要建的文件:

mysql学生相关统计_mysql学生相关统计

 

 

 

1.登录界面:

 

 

mysql学生相关统计_ViewUI_02

 

login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
 <%@page import="com.SqlBean,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=utf-8">
<title>登录界面</title>
</head>
<script language="javascript">
function check(){
 var sid=myform.sid.value;
 var password=myform.password.value;
 if(sid==null||sid==""||password==null||password==""){
 alert("学号和密码不能为空");
 return false;
 }
 return ture;
 } 
</script>
<body>
<center>
<font size="+3" color="#FF3333" face="Terminal">学生信息管理系统</font>
<br />
<form action="check.jsp" method="post" name="myform">
 <table width="268" border="0">
 <tr>
 <td width="48" height="46">学号:</td>
 <td width="210"><input name="sid" type="text" /></td>
 </tr>
 <tr>
 <td height="42">密码:</td>
 <td><input name="password" type="password" /></td>
 </tr>
 <tr>
 <td height="38" colspan="2" align="center">
 <input name="submit" type="submit" value="提交" onClick="return check()"/> 
 <input name="reset" type="reset" value="重置" /></td>
 </tr>
 </table></form>
</center>
</body>
</html>

 

登录页面验证check.jsp

<%@ page language="java" contentType="text/html; charset=gbk"
 pageEncoding="gbk"%>
 <%@page import="com.SqlBean,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=ISO-8859-1">
<title>验证页面登录信息</title>
</head>
<body>
<%
request.setCharacterEncoding("gbk");
String sid=request.getParameter("sid");
String password=request.getParameter("password");
SqlBean db=new SqlBean();
String sql="select * from t_user where sid='"+sid+"'and password='"+password+"'";
out.println(sql);
ResultSet re=db.executeQury(sql);
if(re.next()){
session.setAttribute("sid",sid);
response.sendRedirect("index.html");
}
else{
%>
<script type="text/javascript">
alert("你的学号和密码有误,请重新输入!");
window.location.href="login.jsp";
</script><% } %>
</body>
</html>

 

2.搭建整个页面框架,right.html、top.html、left.html。在left中建框架集index.html.

mysql学生相关统计_javascript_03

 

 

3.显示所有信息页面information.jsp

<%@ page language="java" contentType="text/html; charset=gbk"
 pageEncoding="gbk"%>
 <%@page import="com.SqlBean,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=gbk">
<title>显示所有信息界面</title>
</head>
<body>
<%
SqlBean db=new SqlBean();
ResultSet re=db.executeQury("select * from t_user");
 %>
 <center>
 <font size="+1">学生信息界面显示</font>
 <hr/><br/>
 <table border="1">
 <tr>
 <td width="130">学号</td>
 <td width="130">姓名</td>
 <td width="80">性别</td>
 <td width="310">业余爱好</td>
 <td width="190">专业</td>
 <td width="150">操作</td>
 </tr>
 <%
 while(re.next()){
 %>
 <tr>
 <td width="130"><%=re.getString("sid") %></td>
 <td width="130"><%=re.getString("name") %></td>
 <td width="80"><%=re.getString("sex") %></td>
 <td width="310"><%=re.getString("hobby") %></td>
 <td width="190"><%=re.getString("major") %></td>
 <td width="150"><a href="deletedinfo.jsp?sid=<%=re.getString("sid") %>">删除</a>  
 <a href="updateinfo.jsp?sid=<%=re.getString("sid") %>">修改</a></td>
 </tr>

<%} %>
 </table>
 <%db.close(); %>
 </center>
</body>
</html>

 

4.插入功能

insert.jsp
<%@ page language="java" contentType="text/html; charset=gbk"
 pageEncoding="gbk"%>
<!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=gbk">
<title>添加信息界面</title>
</head>
<script type="text/javascript">
function check(){
 var sid=myform.sid.value;
 var password=myform.name.value;
 if(sid.length!=9){
 alert("学号位数不对,要求9位");
 return false;
 }
 if(sid==null||sid==""||name==null||name==""){
 alert("学号和姓名不能为空!");
 return false;
 }
 return true;
 }
</script>
<body>
<center>
<form action="insertinto.jsp" method="post" name="myform">
<table width="506" height="360" border="1">
<tr>
 <td width="133">学号:</td>
 <td width="357" align="left"><input name="sid" type="text"/> </td>
 </tr><tr>
<td>姓名:</td>
<td align="left"><input name="name" type="text"/> </td>
</tr><tr>
<td>性别:</td>
<td align="left"><input name="sex" type="radio" value="男" checked/> 男<input name="sex" type="radio" value="女"/>女</td>
</tr><tr>
<td>专业:</td>
<td align="left"><select name="major" size="1">
<option value="物联网工程" checked>物联网工程</option>
<option value="网络工程" >网络工程</option>
<option value="电子信息技术">电子信息技术</option>
<option value="通信工程">通信工程</option>
</select> </td>
</tr> 
<tr>
<td>业余爱好:</td>
<td align="left"><input name="hobby" type="checkbox" value="篮球" checked />篮球 
<input name="hobby" type="checkbox" value="足球"/>足球 
<input name="hobby" type="checkbox" value="游戏"/>游戏 
<input name="hobby" type="checkbox" value="唱歌"/>唱歌 
</td>
</tr> 
<tr>
<td colspan="2" align="center"><input name="submit" type="submit" value="添加" onClick="return check()"/>
    <input name="" type="reset" value="重置"/>
</td>
</tr>
</table>
</form>
</center></body>
</html>

insertinto.jsp

 

<%@ page language="java" contentType="text/html; charset=gbk"
 pageEncoding="gbk"%>
 <%@page import="com.SqlBean,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=gbk">
<title>添加信息实现代码</title>
</head>
<body>
<%
request.setCharacterEncoding("gbk");
String sid = request.getParameter("sid");
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String major = request.getParameter("major");
String hobbys[] = request.getParameterValues("hobby");
String hobby = "";
for(String str : hobbys){
 hobby += str + " ";
}
String password = sid.substring(sid.length() - 6,sid.length());
SqlBean db = new SqlBean();
String sq = "select * from t_user where sid='"+sid+"'";
ResultSet re=db.executeQury(sq);
if(re.next()){
db.close();
%>
<script language="javaScript">
alert("该用户已存在");
window.location.href="insert.jsp";
</script>
<%
}
else{
String sql = "insert into t_user values(null,'"+sid+"','"+name+"','"+password+"','"+sex+"','"+major+"','"+hobby+"')";
out.println(sql);
db.execute(sql);
db.close();
response.sendRedirect("information.jsp");
} %>
</body>
</html>

5.删除功能

delete.jsp
<%@ page language="java" contentType="text/html; charset=gbk"
 pageEncoding="gbk"%>
<!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=gbk">
<title>删除学生信息界面设计</title>
</head>
<script language="javascript">
function check(){
var sid=myform.sid.value;if(sid=="null"||sid==""){
alert("学号不能为空!");
return false;
}
return false;
}
return true;
}
</script>
<body>
 <center>
 <font size="+2">删除信息界面设计</font>
 <hr />
 <br />
 <form action="deletedinfo.jsp" method="post" name="myform">
 输入删除学生的学号:
 <input type="text" name="sid" />
 <br />
 <br />
 <input type="submit" value="删除 " οnclick="return check()"/>
 <input type="reset" value="重置"/></form>
 </center>
</body>
</html>

deletedinfo.jsp

<%@ page language="java" contentType="text/html; charset=gbk"
 pageEncoding="gbk"%>
 <%@page import="com.SqlBean,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=gbk">
<title>删除学生信息功能实现</title>
</head>
<body>
<%
 //为避免乱码,设置编码方式
 request.setCharacterEncoding("gbk");
 //获取学号信息
 String sid = request.getParameter("sid");
 //验证学号是否存在
 SqlBean db=new SqlBean();

 String sql="select * from t_user where sid='" +sid+ "' ";
 ResultSet re=db.executeQury(sql);
 if(re.next()){
 sql="delete from t_user where sid='" +sid+ "' ";
 db.execute(sql);
 db.close();
 %>
 <script language="javaScript">
 alert("信息删除成功!!!");
 window.location.href="information.jsp"
 </script>
 <%
 }
 else{
 %>
 <script language="javaScript">
 alert("没有该学号的学生!!!");
 window.location.href="deleted.jsp"
 </script>
 <%
 }
 %>
</body>
</html>

 

6.修改功能

update.jsp

<%@ page language="java" contentType="text/html; charset=gbk"
 pageEncoding="gbk"%>
<!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=gbk">
<title>修改学生信息界面设计</title>
</head>
<script language="javascript">
function check(){
var sid=myform.sid.value;
if(sid==null||sid==""){
alert("学号不能为空!!!");
return false;
}
return true;
}
</script>
<body>
 <center>
 <font size="+2">修改信息界面设计</font>
 <hr />
 <br />
 <form action="updateinfo.jsp" method="post" name="myform">
 输入需要修改学生的学号:
 <input type="text" name="sid" />
 <br />
 <br />
 <input type="submit" value="查看" οnclick="return check()"/>
 <input type="reset" value="重置"/> </form>
 </center>
</body>
</html>

 

updateinfo.jsp

<%@ page language="java" contentType="text/html; charset=gbk"
 pageEncoding="gbk"%>
 <%@page import="com.SqlBean,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=gbk">
<title>修改界面信息</title>
</head>
<body>
 <center>
 <font size="+2">修改学生信息界面设计</font>
 <hr />
 <br />
 </center>
 <%
 //为避免乱码,设置编码方式
 request.setCharacterEncoding("gbk");
 //获取各个信息,不获取确认密码框的信息
 String bpass=request.getParameter("beforepass");
 String sid=request.getParameter("sid");

 //验证原密码是否正确
 SqlBean db = new SqlBean();
 String sql="select * from t_user where sid='"+sid+"'";
 ResultSet re = db.executeQury(sql);
 if(re.next()){
 %>
 <center>
 <form action="updateinformation.jsp" method="post" name="myform">
 <table width="506" height="360" border="1">
 <tr>
 <td width="133">学号:</td>

 <td width="357" align="left">
 <input name="sid" type="text" readonly 
 value="<%=re.getString("sid") %>"/>
  
 </td>
 </tr>

 <tr>
 <td>姓名:</td>
 <td align="left">
 <input name="name" type="text" value="<%=re.getString("name") %>"/>
  
 </td>
 </tr>
 <tr>
 <td>
 性别: 
 </td>
 <td align="left">
 <input name="sex" type="radio" value="男"
 <%if (re.getString("sex").equals("男"))
 out.print("checked");%>/>
 男
 <input name="sex" type="radio" value="女"
 <%if (re.getString("sex").equals("女"))
 out.print("checked");%>/>
 女
 </td>
 </tr>

 <tr>
 <td>业余爱好:</td>
 <td align="left">
 <input name="hobby" type="checkbox" value="篮球"
 <%if (re.getString("hobby").contains("篮球"))
 out.print("checked");%>/>
 篮球 
 <input name="hobby" type="checkbox" value="足球"
 <%if (re.getString("hobby").contains("足球"))
 out.print("checked");%>/>
 足球 
 <input name="hobby" type="checkbox" value="游戏"
 <%if (re.getString("hobby").contains("游戏"))
 out.print("checked");%>/>
 游戏 
 <input name="hobby" type="checkbox" value="唱歌"
 <%if (re.getString("hobby").contains("唱歌"))
 out.print("checked");%>/>
 唱歌 
 </td>
 </tr>
 <tr>
 <td>专业:</td>
 <td align="left">
 <select name="major" size="1">
 <option value="物联网工程" 
 <%if(re.getString("major").equals("物联网工程"))
 out.print("selected");%>>
 物联网工程
 </option>
 <option value="网络工程" 
 <%if(re.getString("major").equals("网络工程"))
 out.print("selected");%>>
 网络工程
 </option>
 <option value="电子信息技术" 
 <%if(re.getString("major").equals("电子信息技术"))
 out.println("selected");%>>
 电子信息技术工程
 </option>
 <option value="通信工程" 
 <%if(re.getString("major").equals("通信工程"))
 out.println("selected");%>>
 通信工程
 </option>
 </select>
 </td>
 </tr>
 <tr>
 <td colspan="2" align="center">
 <input name="submit" type="submit" value="修改" οnclick="return check()"/>

 </td>
 </tr>
 </table>
 </form>

 </center>
 <%
 }else{
 db.close();

 %>
 <script language="javaScript">
 alert("你输入的学号有误");
 window.location.href="update.jsp";
 </script>
 <%
 }
 %>
</body>
</html>

updateinformation.jsp

 

<%@ page language="java" contentType="text/html; charset=gbk"
 pageEncoding="gbk"%>
 <%@page import="com.SqlBean,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=gbk">
<title>修改信息实现代码</title>
</head>
<body>
<%
request.setCharacterEncoding("gbk");
String sid = request.getParameter("sid");
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String major = request.getParameter("major");
String hobbys[] = request.getParameterValues("hobby");
String hobby = "";
for(String str : hobbys){
 hobby += str + " ";
}
String password = sid.substring(sid.length() - 6,sid.length());
SqlBean db = new SqlBean();
String sql = "update t_user set name='"
 + name + "',password='" + password + "',sex='"+sex+"',major='" + major + "',hobby='" + hobby + "' where sid='" + sid + "' ";db.execute(sql);
db.close();
%>
<script language="javaScript">
alert("修改成功,密码为初始密码!");
window.location.href="information.jsp";
</script>
</body>
</html>

 

 

运行截图:

mysql学生相关统计_嵌入式_04

mysql学生相关统计_javascript_05

mysql学生相关统计_数据库_06

mysql学生相关统计_数据库_07