所用工具:myeclipse、dreamweaver CS6、mysql-front、tomcat、mysql-connector-java-5.1.12-bin
功能:用戶通過輸入密碼登錄進系統,可以對學生信息進行添加、刪除、修改基本信息和密碼以及查詢等操作。
所有需要建的文件:

1.登錄界面:

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.

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="刪除 " onclick="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="查看" onclick="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="修改" onclick="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>
運行截圖:




