java_web学生信息管理系统-精品
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Web程序设计
—学生信息管理系统
姓名:鲁超、刘千飞、肖伟超
万联播、张明明、白浩
班级:软件0901
时间:2011/12/22
一、实验目的
熟练运用web开发技术设计完成一个学生信息管理系统。
二、实验原理
功能要求:
基于B/S架构实现学生信息的增\删\改\查\展示功能,实现完整的应用构建和界面设计。
技术要求:
基于mysql或mssqlserver数据库,以Tomcat为应用服务器,可使用Jsp+Servelt+Javabean完成,鼓励使用struts,Hibernate框架完成设计。
三、实验分组
四、实验内容
登陆主页源代码:
login.html:
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312"> <title>登陆模块</title>
</head>
<body bgcolor=lightblue bgcolor="FFFFFF">
<h1align="center"><b>欢迎登陆学生信息管理系统</b></h1>
<hr>
<form action="forward.jsp"method="post">
<p></p>
<table width="52%"border="2"align="center">
<tr bgcolor="#FFFFCC">
<td align="center"width="43%"><div align="center">用户名:</div></td> <td width="57%"><div align="left">
<input type="text"name="username">
</div></td>
</tr>
<tr bgcolor="#CCFF99">
<td align="center"width="43%"><div align="center">密码:</div></td> <td width="57"><div align="left">
<input type="password"name="password">
</div></td>
</tr>
</table>
<p align="center">
<input type="reset"name="Reset"value="重置">
<input type="submit"name="Submit2"value="提交">
</p>
</form>
</body>
</html>
forward.jsp:
<%@page language="java"contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312"> <title>login forward</title>
</head>
<body bgcolor=lightblue>
<%
String username=null;
String password=null;
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
username=request.getParameter("username");
password=request.getParameter("password");
if(!username.equals("")&&!password.equals(""))
{
%>
<jsp:forward page="login_ok.jsp">
<jsp:param name="username"value='<%=username%>'/>
<jsp:param name="username"value='<%=password%>'/>
</jsp:forward>
<%
}
else
{
%>
<jsp:forward page="error.jsp">
<jsp:param name="username"value='<%=username%>'/>
<jsp:param name="username"value='<%=password%>'/>
</jsp:forward>
<%
}
%>
</body>
</html>
login_ok.jsp:
<%@page language="java"contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312">
<title>Insert title here</title>
<style type="text/css">
input{
color:red;
font-size:12pt;
}
</style>
</head>
<body bgcolor=lightblue>
<center><h1>欢迎您使用学生管理系统</h1></center>
<hr>
<%
String username=null;
String password=null;
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
username=request.getParameter("username");
password=request.getParameter("password");
out.println("登陆成功,用户名[<font color='red'>"+username+"</font>],"); out.println("密码[<font color='red'>"+password+"</font>]");
%>
<br>
<p align="center">
请选择您要进行的操作:
<form action="p_cha.html"method="post">
<input type="submit"name="cha"value="查询">
</form>
<form action="p_shan.html"method="post">
<input type="submit"name="shan"value="删除">
</form>
<form action="p_gai.html"method="post">
<input type="submit"name="gai"value="修改">
</form>
<form action="p_zeng.html"method="post">
<input type="submit"name="zeng"value="增加">
</form>
</body>
</html>
error.jsp:
<%@page language="java"contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312"> <title>Error</title>
</head>
<body bgcolor=lightblue>
<center><h1>欢迎您使用学生管理系统</h1></center>
<%
String username=null;
String password=null;
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
username=request.getParameter("username");
password=request.getParameter("password");
out.println("您输入的用户名[<font color='red'>"+username+"</font>],"); out.println("和密码[<font color='red'>"+password+"</font>]有一项为空,请重新输入:");
%>
<a href="login.html">---返回重新登陆---</a>
</body>
</html>
学生信息增加模块:
p_zeng.html:
<%@page language="java"contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312">
<title>Insert title here</title>
<style type="text/css">
input{
color:red;
font-size:12pt;
}
</style>
</head>
<body bgcolor=lightblue>
<center><h1>欢迎您使用学生管理系统</h1></center>
<hr>
<%
String username=null;
String password=null;
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
username=request.getParameter("username");
password=request.getParameter("password");
out.println("登陆成功,用户名[<font color='red'>"+username+"</font>],"); out.println("密码[<font color='red'>"+password+"</font>]");
%>
<br>
<p align="center">
请选择您要进行的操作:
<form action="p_cha.html"method="post">
<input type="submit"name="cha"value="查询">
</form>
<form action="p_shan.html"method="post">
<input type="submit"name="shan"value="删除">
</form>
<form action="p_gai.html"method="post">
<input type="submit"name="gai"value="修改">
</form>
<form action="p_zeng.html"method="post">
<input type="submit"name="zeng"value="增加">
</form>
</body>
</html>
zeng.jsp:
<%@page language="java"contentType="text/html; charset=gb2312"
pageEncoding="gb2312"import="java.sql.*"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"
"/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312">
<title>call stored procedure</title>
</head>
<body bgcolor=lightblue>
<%
int PAGESIZE=3;
int pageCount=0;
int curPage=1;
java.sql.Connection conn=null;
PreparedStatement pstmt=null;
Statement stmt=null;
ResultSet rs=null;
String[]
cloStr={"sno","sname","cclass","sex","age","nation","clname","place"} ;
String[] showStr={"学生编号","学生姓名","所在年级","性别","年龄","民族","专业","住址"};
String sno,sname,cclass,sex,age,nation,clname,place;
String strURL="jdbc:mysql://localhost/test";
String strDBUser="root";
String strDBPwd="123";
try
{
Class.forName("com.mysql.jdbc.Driver");
conn=java.sql.DriverManager.getConnection(strURL,strDBUser,strDBPwd);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
out.println("您输入的信息有误,请查证后再重新输入!");
}
catch(Exception ex)
{
ex.printStackTrace();
out.println("您输入的信息有误,请查证后再重新输入!");
}
try{
sno=request.getParameter("sno");
byte no[]=sno.getBytes("ISO-8859-1");
sno=new String(no);
sname=request.getParameter("sname");
byte name[]=sname.getBytes("ISO-8859-1");
sname=new String(name,"gb2312");
cclass=request.getParameter("cclass");
byte clss[]=cclass.getBytes("ISO-8859-1");
cclass=new String(clss,"gb2312");
sex=request.getParameter("sex");
byte ex[]=sex.getBytes("ISO-8859-1");
sex=new String(ex,"gb2312");
age=request.getParameter("age");
byte ge[]=age.getBytes("ISO-8859-1");
age=new String(ge);
nation=request.getParameter("nation");
byte tion[]=nation.getBytes("ISO-8859-1");
nation=new String(tion,"gb2312");
clname=request.getParameter("clname");
byte cname[]=clname.getBytes("ISO-8859-1");
clname=new String(cname,"gb2312");
place=request.getParameter("place");
byte lace[]=place.getBytes("ISO-8859-1");
place=new String(lace,"gb2312");
String sqlll="insert into
S(sno,sname,cclass,sex,age,nation,clname,place)
values('"+sno+"','"+sname+"','"+cclass+"','"+sex+"','"+age+"','"+nati on+"','"+clname+"','"+place+"')";
pstmt=conn.prepareStatement(sqlll);
int count3=pstmt.executeUpdate();//插入
String sqllll="select * from S";
stmt=conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCU R_READ_ONLY);
rs=stmt.executeQuery(sqllll);
st();
int size=rs.getRow();
pageCount=(size%PAGESIZE==0)?(size/PAGESIZE):(size/PAGESIZE+1);
}
catch(Exception ex)
{
ex.printStackTrace();
out.println("您输入的信息有误,请查证后再重新输入!");
}
//获取想要显示的页数:
String integer=request.getParameter("curPage");
if(integer==null)
{
integer="1";
}
try {
curPage=Integer.parseInt(integer);
}
catch(NumberFormatException e)
{curPage=1;
}
if(curPage<=1)
{
curPage=1;
}
if(curPage>=pageCount)
{
curPage=pageCount;
}
//如果要显示第curPage页,那么游标应移到posion的值是:
int posion=(curPage-1)*PAGESIZE+1;
rs.absolute(posion); // 设置游标的位置
%>
<br>
<table border=1cellspacing=0width='100%'class=listFram
id="maintable">
<tr>
<%
for(int i=0;i<showStr.length;i++)
{
out.println("<td height=5>");
out.println("<div align='center'>"+showStr[i]+"</div></td>");
}
%>
</tr>
<%
int count=0;
do{
if(count>=PAGESIZE)
break;
out.println("<tr>");
for(int i=0;i<cloStr.length;i++)
{
out.println("<td height=5>");
out.println("<div
align='center'>"+rs.getString(cloStr[i])+"</div></td>");
}
out.println("</tr>");
count++;
}while(rs.next());
%>
</table>
<a href = "cha.jsp?curPage=1">首页</a>
<a href = "cha.jsp?curPage=<%=curPage-1%>">上一页</a>
<a href = "cha.jsp?curPage=<%=curPage+1%>">下一页</a>
<a href = "cha.jsp?curPage=<%=pageCount%>">尾页</a>
第<%=curPage%>页/共<%=pageCount%>页
<FORM action=""method=get>
输入页码数<Input Type=text name=curPage size=4>
<Input Type=submit name=g value="跳转">
</FORM>
</body>
</html>
学生信息删除模块:
p_shan.html:
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312"> <title>Insert title here</title>
<style type="text/css">
h3{
color:red;
}
</style>
</head>
<body bgcolor=lightblue>
<center><h1>欢迎您使用学生管理系统</h1></center>
<p align="center">
<hr>
<div align="right"><a href="login_ok.jsp">返回首页</a></div>
<h3>删除操作</h3>
<table align="center">
<tr>
<td>
请输入学生学号:
<form target="mainFrame"action="shan_xuehao.jsp"method="post">
<input type="text"name="sno"size=20>
<input type="submit"name="su"value="按学号删除">
</form>
</td>
<td>
请输入学生姓名:
<form target="mainFrame"action="shan_xingming.jsp"method="post"> <input type="text"name="sname"size=20>
<input type="submit"name="su"value="按姓名删除">
</form>
</td>
</tr>
<tr>
<td>
请输入学生性别:
<form target="mainFrame"action="shan_xingbie.jsp"method="post">
<input type="text"name="sex"size=20>
<input type="submit"name="su"value="按性别删除">
</form>
</td>
<td>
请输入学生住址:
<form target="mainFrame"action="shan_dizhi.jsp"method="post">
<input type="text"name="place"size=20>
<input type="submit"name="su"value="按地址删除">
</form>
</td>
</tr>
</table>
<p align="center">
<iframe width=700height=700name="mainFrame"frameborder="no">
</iframe>
</body>
</html>
①按学号删除:
Shan_xuehao.jsp:
<%@page language="java"contentType="text/html; charset=gb2312"
pageEncoding="gb2312"import="java.sql.*"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"
"/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312"> <title>call stored procedure</title>
</head>
<body bgcolor=lightblue>
<%
int PAGESIZE=3;
int pageCount=0;
int curPage=1;
java.sql.Connection conn=null;
PreparedStatement pstmt=null;
Statement stmt=null;
ResultSet rs=null;
String[]
cloStr={"sno","sname","cclass","sex","age","nation","clname","place"} ;
String[] showStr={"学生编号","学生姓名","所在年级","性别","年龄","民族","专
业","住址"};
String sno;
if(conn==null)
{
String strURL="jdbc:mysql://localhost/test";
String strDBUser="root";
String strDBPwd="123";
try
{
Class.forName("com.mysql.jdbc.Driver");
out.println("连接数据库成功......");
conn=java.sql.DriverManager.getConnection(strURL,strDBUser,strDBPwd);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
out.println("ClassNotFoundException111");
}
catch(Exception ex)
{
ex.printStackTrace();
out.println("Exception11");
}
}
try{
sno=request.getParameter("sno");
byte no[]=sno.getBytes("ISO-8859-1");
sno=new String(no);
String sql="delete from S where sno="+sno;
pstmt=conn.prepareStatement(sql);
int count=pstmt.executeUpdate();//删除
String sqllll="select * from S";
stmt=conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.C ONCUR_READ_ONLY);
rs=stmt.executeQuery(sqllll);
st();
int size=rs.getRow();
pageCount=(size%PAGESIZE==0)?(size/PAGESIZE):(size/PAGESIZE+1);
}
catch(Exception ex)
{
ex.printStackTrace();
out.println("您输入的信息有误,请查证后再重新输入!");
}
//获取想要显示的页数:
String integer=request.getParameter("curPage");
if(integer==null)
{
integer="1";
}
try {
curPage=Integer.parseInt(integer);
}
catch(NumberFormatException e)
{curPage=1;
}
if(curPage<=1)
{
curPage=1;
}
if(curPage>=pageCount)
{
curPage=pageCount;
}
//如果要显示第curPage页,那么游标应移到posion的值是:
int posion=(curPage-1)*PAGESIZE+1;
rs.absolute(posion); // 设置游标的位置
%>
<br>
<table border=1cellspacing=0width='100%'class=listFram
id="maintable">
<tr>
<%
for(int i=0;i<showStr.length;i++)
{
out.println("<td height=5>");
out.println("<div align='center'>"+showStr[i]+"</div></td>");
}
%>
</tr>
<%
int count=0;
do{
if(count>=PAGESIZE)
break;
out.println("<tr>");
for(int i=0;i<cloStr.length;i++)
{
out.println("<td height=5>");
out.println("<div
align='center'>"+rs.getString(cloStr[i])+"</div></td>");
}
out.println("</tr>");
count++;
}while(rs.next());
%>
</table>
<a href = "cha.jsp?curPage=1">首页</a>
<a href = "cha.jsp?curPage=<%=curPage-1%>">上一页</a>
<a href = "cha.jsp?curPage=<%=curPage+1%>">下一页</a>
<a href = "cha.jsp?curPage=<%=pageCount%>">尾页</a>
第<%=curPage%>页/共<%=pageCount%>页
<FORM action=""method=get>
输入页码数<Input Type=text name=curPage size=4>
<Input Type=submit name=g value="跳转">
</FORM>
</body>
</html>
②其中按姓名(shan_xuehao.jsp)、按性别
(shan_xingbie.jsp)、按地址(shan_dizhi.jsp)删除基本同上,此处代码省略。
学生信息修改模块:
p_gai.html:
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312"> <title>Insert title here</title>
<style type="text/css">
h3{
color:red;
}
</style>
</head>
<body bgcolor=lightblue>
<center><h1>欢迎您使用学生管理系统</h1></center>
<p align="center">
<hr>
<div align="right"><a href="login_ok.jsp">返回首页</a></div>
<h3>修改操作</h3>
请输入要修改的学生学号:
<form action=cha_xuehao.jsp method="post"target="mainFrame">
<input type="text"name="number"size=20>
<input type="submit"name="su"value="查询">
</form>
<table align="center"width=430>
<tr>
<td>请输入新的学生信息:
<form target="mainFrame"action="gai.jsp"method="post">
学号:<input type="text"name="sno"size=20>
姓名:<input type="text"name="sname"size=20>
年级:<input type="text"name="cclass"size=20>
性别:<input type="text"name="sex"size=20>
年龄:<input type="text"name="age"size=20>
名族:<input type="text"name="nation"size=20>
专业:<input type="text"name="clname"size=20>
地址:<input type="text"name="place"size=20>
<p align="center">
<input type="submit"name="gai"value="提交">
</form>
</td>
</tr>
</table>
<p align="center">
<iframe width=700height=700name="mainFrame"frameborder="no">
</iframe>
</body>
</html>
gai.jsp:
<%@page language="java"contentType="text/html; charset=gb2312"
pageEncoding="gb2312"import="java.sql.*"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"
"/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312">
<title>call stored procedure</title>
</head>
<body bgcolor=lightblue>
<%
java.sql.Connection conn=null;
PreparedStatement pstmt=null;
Statement stmt=null;
ResultSet rs=null;
String[]
cloStr={"sno","sname","cclass","sex","age","nation","clname","place"} ;
String[] showStr={"学生编号","学生姓名","所在年级","性别","年龄","民族","专业","住址"};
String sno,sname,cclass,sex,age,nation,clname,place;
String strURL="jdbc:mysql://localhost/test";
String strDBUser="root";
String strDBPwd="123";
try
{
Class.forName("com.mysql.jdbc.Driver");
conn=java.sql.DriverManager.getConnection(strURL,strDBUser,strDBPwd);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
out.println("您输入的信息有误,请查证后再重新输入!");
}
catch(Exception ex)
{
ex.printStackTrace();
out.println("您输入的信息有误,请查证后再重新输入!");
}
try{
sno=request.getParameter("sno");
byte no[]=sno.getBytes("ISO-8859-1");
sno=new String(no);
sname=request.getParameter("sname");
byte name[]=sname.getBytes("ISO-8859-1");
sname=new String(name,"gb2312");
cclass=request.getParameter("cclass");
byte clss[]=cclass.getBytes("ISO-8859-1");
cclass=new String(clss,"gb2312");
sex=request.getParameter("sex");
byte ex[]=sex.getBytes("ISO-8859-1");
sex=new String(ex,"gb2312");
age=request.getParameter("age");
byte ge[]=age.getBytes("ISO-8859-1");
age=new String(ge);
nation=request.getParameter("nation");
byte tion[]=nation.getBytes("ISO-8859-1");
nation=new String(tion,"gb2312");
clname=request.getParameter("clname");
byte cname[]=clname.getBytes("ISO-8859-1");
clname=new String(cname,"gb2312");
place=request.getParameter("place");
byte lace[]=place.getBytes("ISO-8859-1");
place=new String(lace,"gb2312");
String sql="update S set
sname='"+sname+"',cclass='"+cclass+"',sex='"+sex+"',age="+age+",natio n='"+nation+"',clname='"+clname+"',place='"+place+"' where
sno="+sno+"";
pstmt=conn.prepareStatement(sql);
int count=pstmt.executeUpdate();//更新或修改
String sqllll="select * from S where sno"+"="+"'"+sno+"'";
stmt=conn.createStatement();
rs=stmt.executeQuery(sqllll);
}
catch(Exception ex)
{
ex.printStackTrace();
out.println("您输入的信息有误,请查证后再重新输入!");
}
%>
<br>
<table border=1cellspacing=0width='100%'class=listFram
id="maintable">
<tr>
<%
for(int i=0;i<showStr.length;i++)
{
out.println("<td height=5>");
out.println("<div align='center'>"+showStr[i]+"</div></td>");
}
%>
</tr>
<%
while(rs.next())
{
out.println("<tr>");
for(int i=0;i<cloStr.length;i++)
{
out.println("<td height=5>");
out.println("<div
align='center'>"+rs.getString(cloStr[i])+"</div></td>");
}
out.println("</tr>");
}
%>
</table>
</body>
</html>
学生信息查询模块:
p_cha.html:
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312"> <title>Insert title here</title>
<style type="text/css">
h3{
color:red;
}
</style>
</head>
<body bgcolor=lightblue>
<center><h1>欢迎您使用学生管理系统</h1></center>
<p align="center">
<hr>
<div align="right"><a href="login_ok.jsp">返回首页</a></div>
<h3>查询操作</h3>
<table align="center">
<tr>
<td>
请输入学生学号:
<form target="mainFrame"action="cha_xuehao.jsp"method="post">
<input type="text"name="number"size=20>
<input type="submit"name="su"value="按学号查询">
</form>
</td>
<td>
请输入学生性别:
<form target="mainFrame"action="cha_xingbie.jsp"method="post">
<input type="text"name="number"size=20>
<input type="submit"name="su"value="按性别查询">
</form>
</td>
</tr>
<tr>
<td>
请输入学生住址:
<form target="mainFrame"action="cha_dizhi.jsp"method="post">
<input type="text"name="number"size=20>
<input type="submit"name="su"value="按地址查询">
</form>
</td>
<td>。