之前发布过一篇基于C++的学生信息管理系统,学完Javaweb之后,使用jsp语言完成一个在线学生信息管理系统,更加的方便快捷。
由于代码文件数量较多,此处仅给出部分源码,完整源码可通过下方链接下载。
本系统使用MyEclipse+MySQL实现
学生身体体质信息管理系统:描述-一个学生身体体质的信息有:有id (序号,整型),name(姓名,字符串),sex (性别,字符串),age (年龄,整型),weight (体重,实型),hight(身高,实型)。存放学生体质信息的数据库为students,数据表为stu_info。 要求,利用JDBC技术实现对学生身体体质信息的管理。(该系统请采用JSP+JavaBean技术编写)
数据库表设计如下:
addStudent.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'addStudent.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<script type="text/javascript">
function checkform(){
if(document.getElementById("id").value==""){
alert("请输入学生的学号");
return false;
}
if(document.getElementById("name").value==""){
alert("请输入学生的姓名");
return false;
}
if(document.getElementById("sex").value==""){
alert("请输入学生的性别");
return false;
}
if(document.getElementById("age").value==""){
alert("请输入学生的年龄");
return false;
}
if(document.getElementById("weight").value==""){
alert("请输入学生的体重");
return false;
}
if(document.getElementById("hight").value==""){
alert("请输入学生的身高");
return false;
}
}
</script>
<body>
<form action= "insertDB.jsp" method="post">
<table border="0" width="238" height="252" align="center">
<tr><th colspan="2">添加学生信息</th></tr>
<tr> <td>学号</td> <td><input type="text" id="id" name="id"></td> </tr>
<tr> <td>姓名</td> <td><input type="text" id="name" name="name"></td> </tr>
<tr> <td>性别</td> <td><input type="text" id="sex" name="sex" ></td> </tr>
<tr> <td>年龄</td> <td><input type="text" id="age" name="age"></td> </tr>
<tr> <td>体重</td> <td><input type="text" id="weight" name="weight"></td> </tr>
<tr> <td>身高</td> <td><input type="text" id="hight" name="hight"></td> </tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="提 交" onclick="return checkform()">
<input type="reset" value="取 消">
</td>
</tr>
</table>
</form>
</body>
</html>
findStudent.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'SelectAll.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<center>
<h1>学生信息</h1>
</center>
<table align="center" width="1000px" cellpadding="0px" cellspacing="0px" border="1px" style="border:1px solid gray; border-collapse:collapse">
<tr>
<td colspan="7">
</td>
</tr>
<tr>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
<th>体重</th>
<th>身高</th>
<th>操作</th>
</tr>
<%
request.setCharacterEncoding("utf-8");
Connection conn=null; //声明数据库连接对象
PreparedStatement stm=null; //声明数据库操作对象
ResultSet rs=null; //声明查询结果集对象,对于更新操作,可不声明
String driverName = "com.mysql.jdbc.Driver"; //驱动程序名
String userName = "root"; //数据库用户名
String userPwd = "root"; //指定用户密码
String dbName = "student"; //指定数据库名字
String url1="jdbc:mysql://localhost:3306/"+dbName;
String url2 ="?user="+userName+"&password="+userPwd;
String url3="&useUnicode=true&characterEncoding=UTF-8&useSSL=false";
String url =url1+url2+url3; //形成带数据库读写编码的数据库连接字
try {
Class.forName(driverName);
conn=DriverManager.getConnection(url);
//out.println("连接数据库成功"+"<br>");
String sex=request.getParameter("sex");
Float w1=Float.parseFloat(request.getParameter("w1"));
Float w2=Float.parseFloat(request.getParameter("w2"));
String sql="select * from students_info where sex=? and weight>=? and weight<=?";
stm=conn.prepareStatement(sql);
stm.setString(1, sex);
stm.setFloat(2, w1);
stm.setFloat(3, w2);
rs=stm.executeQuery();
while(rs.next()){ %>
<tr align="center">
<td><%=rs.getInt("id") %></td>
<td><%=rs.getString("name") %></td>
<td><%=rs.getString("sex") %></td>
<td><%=rs.getString("age") %></td>
<td><%=rs.getFloat("weight") %></td>
<td><%=rs.getFloat("height") %></td>
<td><a href="#">修改</a>|<a href="#">删除</a></td>
</tr>
<%}
}catch(Exception e){
e.printStackTrace();
}
if(rs!=null){
rs.close();
}
if(stm!=null){
stm.close();
}
if(conn!=null){
conn.close();
}
%>
</table>
</body>
</html>
此处仅给出两个jsp文件实现,文件内部结构如下所示:
本系统中还使用了Javabean,结构如下
最后给出效果图:
系统主页面
学生信息页面
学生信息查询
添加学生信息
完整源码下载链接
基于Javaweb的学生信息管理系统