效果图:
初始页:
核心页:
增加学生:
修改:
代码:
index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="stu?mark=query">查找全部学生</a>
</body>
</html>
list1.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
</script>
</head>
<body>
<center>
<a href="add.jsp">增加学生</a><br/>
<table border="1" width="50%">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>身高</th>
<th>操作</th>
</tr>
<c:forEach items="${list}" var="stu">
<tr>
<td>${stu.name}</td>
<td>${stu.age}</td>
<td>${stu.height}</td>
<td><a href="stu?mark=update&sid=${stu.sid}">修改</a>|<a href="stu?mark=delete&sid=${stu.sid}">删除</a></td>
</tr>
</c:forEach>
</table>
</center>
</body>
</html>
add.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<center>
<h5>---添加学生信息---</h5>
<form action="stu">
<input type="hidden" name="mark" value="add"/>
<table>
<tr>
<td>姓名:</td>
<td><input name="username"/></td>
</tr>
<tr>
<td>年龄:</td>
<td><input name="age"/></td>
</tr>
<tr>
<td>身高:</td>
<td><input name="height"/></td>
</tr>
<tr>
<td colspan="2"align="center"><input type="submit" value="增加"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
update.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<center>
<h5>---修改学生信息---</h5>
<form action="stu">
<input type="hidden" name="mark" value="updateInfo"/>
<input type="hidden" name="sid" value="${stu.sid}"/>
<table>
<tr>
<td>姓名:</td>
<td><input name="username" value="${stu.name}"/></td>
</tr>
<tr>
<td>年龄:</td>
<td><input name="age" value="${stu.age}"/></td>
</tr>
<tr>
<td>身高:</td>
<td><input name="height" value="${stu.height}"/></td>
</tr>
<tr>
<td colspan="2"align="center"><input type="submit" value="修改"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
Student.java:
package text.bean;
public class Student {
private Integer sid;
private String name;
private Integer age;
private Integer height;
public Integer getSid() {
return sid;
}
public void setSid(Integer sid) {
this.sid = sid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
StudentDao.java:
package text.dao;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.junit.Test;
import text.v2.c3p0