使⽤jsp对数据库信息的增删改查
效果图:
初始页:
核⼼页:
增加学⽣:
修改:
代码:
走遍美国 mp3
index.jsp:
<%@ taglib prefix="c" uri="/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta chart="UTF-8">
<title>Inrt title here</title>
</head>
<body>
<a href="stu?mark=query">查找全部学⽣</a>
berrk
</body>
</html>
list1.jsp:
<%@ page language="java" contentType="text/html; chart=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta chart="UTF-8">
<title>Inrt 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:
<head>
<meta chart="UTF-8">
<title>Inrt title here</title>冲上云霄2插曲英文歌
</head>
<body>
<center>
<h5>---添加学⽣信息---</h5>
<form action="stu">
<input type="hidden" name="mark" value="add"/>
<table>
<tr>
<td>姓名:</td>
<td><input name="urname"/></td>
</tr>
<tr>
<td>年龄:</td>
<td><input name="age"/></td>
2012年四川高考语文
</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:
<head>
<meta chart="UTF-8">
<title>Inrt 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="urname" 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(){wideawake
return sid;
}
public void tSid(Integer sid){
this.sid = sid;
}
public String getName(){
return name;
}
public void tName(String name){
this.name = name;
}
public Integer getAge(){
return age;
}extradition
public void tAge(Integer age){
this.age = age;
}
public Integer getHeight(){
return height;
}
public void tHeight(Integer height){
this.height = height;
}
2016考研时间
}
StudentDao.java:
package text.dao;
import java.sql.SQLException;
import java.util.List;
import s.dbutils.QueryRunner;
import s.dbutils.handlers.BeanHandler; import s.dbutils.handlers.BeanListHandler; import org.junit.Test;
import text.v2.c3p0.ComboPooledDataSource;
import text.bean.Student;
public class StudentDao {
@Test
public void method(){
List<Student> list =findAll();
for(Student stu : list){
同位语从句的引导词System.out.Name());
}
}
@Test
public void method01(){
Student stu =findById(5);
System.out.Name());