附:接上篇文章,本文章介绍的是代码的具体实施
上篇文章链接
图书信息管理的增删改查(一)
一、接下来我们来写代码
1、首先我们先写图书信息的对象类和图书分类的对象类
a、图书信息的对象类
package com.hnpi.model;
/**
* 图书的属性和方法
* @author Administrator
*
*/
public class Book {
private int id;
private String bookName;
private String bookAuthor;
private String bookIsbn;
private String bookPublish;
private int classifyId;
public Book() {
super();
// TODO Auto-generated constructor stub
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getBookAuthor() {
return bookAuthor;
}
public void setBookAuthor(String bookAuthor) {
this.bookAuthor = bookAuthor;
}
public String getBookIsbn() {
return bookIsbn;
}
public void setBookIsbn(String bookIsbn) {
this.bookIsbn = bookIsbn;
}
public String getBookPublish() {
return bookPublish;
}
public void setBookPublish(String bookPublish) {
this.bookPublish = bookPublish;
}
public int getClassifyId() {
return classifyId;
}
public void setClassifyId(int classifyId) {
this.classifyId = classifyId;
}
}
b、图书分类的对象类
package com.hnpi.model;
/**
* 图书分类的属性和方法
* @author Administrator
*
*/
public class Classify {
private int classifyId;
private String classifyName;
//无参构造方法
public Classify() {
super();
// TODO Auto-generated constructor stub
}
public int getClassifyId() {
return classifyId;
}
public void setClassifyId(int classifyId) {
this.classifyId = classifyId;
}
public String getClassifyName() {
return classifyName;
}
public void setClassifyName(String classifyName) {
this.classifyName = classifyName;
}
}
2、对象类写完后,我们来写两个接口,来存放增删改查的四个方法
a、图书信息接口
package com.hnpi.dao;
import com.hnpi.model.Book;
import java.util.List;
public interface BookDao {
/**
* 删除图书
* @param id
* @return
*/
boolean delete(int id);
/**
* 查询图书
* @return
*/
List<Book> select();
/**
* 添加图书
* @param book
* @return
*/
boolean add(Book book);
/**
* 更改图书
* @param book
* @return
*/
boolean update(Book book);
}
b、图书分类接口
package com.hnpi.dao;
import com.hnpi.model.Classify;
import java.util.List;
public interface ClassifyDao {
/**
* 删除图书分类
* @param classifyId
* @return
*/
boolean delete(int classifyId);
/**
* 查询图书分类
* @return
*/
List<Classify> select();
/**
*添加图书分类
* @param classify
* @return
*/
boolean add(Classify classify);
/**
* 更新图书分类
* @param classify
* @return
*/
boolean update(Classify classify);
}
3、接口写完,那么就该实现这些接口里面的方法了
a、在实现接口前,我们先来写一个和SQL server数据库做连接的一个DBUtil类,里面分别包括了连接数据库和关闭资源接口的方法,具体代码如下:
package com.hnpi.util;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class DBUtil {
/**
* 连接数据库 方法
* @return
*/
public static Connection getConn() {
Connection conn = null;
try {
Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
//方法里的分别是,数据库的地址,用户名,密码
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName = BOOK","sa", "1");
} catch (ClassNotFoundException classNotFoundException) {
classNotFoundException.printStackTrace();
} catch (SQLException sqlException) {
sqlException.printStackTrace();
}
return conn;
}
/**
* 关闭资源 方法
* @param conn
* @param ps
* @param rs
*/
public static void close(Connection conn, PreparedStatement ps, ResultSet rs) {
try {
if (conn != null)
conn.close();
if (ps != null)
ps.close();
if (rs != null)
rs.close();
} catch (SQLException sqlException) {
sqlException.printStackTrace();
}
}
}
b、然后来实现接口的方法
图书信息的增删改查方法如下:
package com.hnpi.dao.impl;
import com.hnpi.dao.BookDao;
import com.hnpi.model.Book;
import com.hnpi.util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class BookDaoImpl implements BookDao {
PreparedStatement ps = null;
ResultSet rs = null;
Connection conn = null;
/**
* 删除图书方法
*/
public boolean delete(int id) {
try {
conn = DBUtil.getConn();
String sql = "delete from book where id = ?";
ps = conn.prepareStatement(sql);
ps.setInt(1, id);
int result = ps.executeUpdate();
if (result > 0) {
return true;
} else {
return false;
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
return false;
} finally {
DBUtil.close(conn, ps, rs);
}
}
/**
* 查询图书方法
*/
public List<Book> select() {
//写一个数组,把查询到的数据放到数组里面
List<Book> bookList = new ArrayList<Book>();
try {
conn = DBUtil.getConn();
String sql = "select * from book";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
Book book = new Book();
book.setId(rs.getInt(1));
book.setBookName(rs.getString(2));
book.setBookAuthor(rs.getString(3));
book.setBookIsbn(rs.getString(4));
book.setBookPublish(rs.getString(5));
book.setClassifyId(rs.getInt(6));
bookList.add(book);
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
} finally {
DBUtil.close(conn, ps, rs);
}
return bookList;
}
/**
* 添加图书方法
*/
public boolean add(Book book) {
try {
conn = DBUtil.getConn();
String sql = "insert into book (id,book_name,book_author,book_isbn,book_publish,classify_id) values(?,?,?,?,?,?)";
ps = conn.prepareStatement(sql);
ps.setInt(1, book.getId());
ps.setString(2, book.getBookName());
ps.setString(3, book.getBookAuthor());
ps.setString(4, book.getBookIsbn());
ps.setString(5, book.getBookPublish());
ps.setInt(6, book.getClassifyId());
int result = ps.executeUpdate();
if (result > 0) {
return true;
} else {
return false;
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
return false;
} finally {
DBUtil.close(conn, ps, rs);
}
}
/**
* 更新图书方法
*/
public boolean update(Book book) {
try {
conn = DBUtil.getConn();
String sql = "update book set book_name = ?, book_author = ?, book_isbn = ?, book_publish = ?, classify_id = ? where id = '"+ book.getId()+"' ";
ps = conn.prepareStatement(sql);
ps.setString(1, book.getBookName());
ps.setString(2, book.getBookAuthor());
ps.setString(3, book.getBookIsbn());
ps.setString(4, book.getBookPublish());
ps.setInt(5, book.getClassifyId());
int result = ps.executeUpdate();
if (result > 0) {
return true;
} else {
return false;
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
return false;
} finally {
DBUtil.close(conn, ps, rs);
}
}
}
图书分类的增删改查方法,代码如下:
package com.hnpi.dao.impl;
import com.hnpi.dao.ClassifyDao;
import com.hnpi.model.Book;
import com.hnpi.model.Classify;
import com.hnpi.util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class ClassifyDaoImpl implements ClassifyDao {
PreparedStatement ps = null;
ResultSet rs = null;
Connection conn = null;
/**
* 删除图书分类方法
*/
public boolean delete(int classifyId) {
try {
conn = DBUtil.getConn();
String sql = "delete from classify where classify_id = ?";
ps = conn.prepareStatement(sql);
ps.setInt(1, classifyId);
int result = ps.executeUpdate();
if (result > 0) {
return true;
} else {
return false;
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
return false;
} finally {
DBUtil.close(conn, ps, rs);
}
}
/**
* 查询图书分类方法
*/
public List<Classify> select() {
List<Classify> classifyList = new ArrayList<Classify>();
try {
conn = DBUtil.getConn();
String sql = "select * from classify";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
Classify classify = new Classify();
classify.setClassifyId(rs.getInt("classify_id"));
classify.setClassifyName(rs.getString("classify_name"));
classifyList.add(classify);
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
} finally {
DBUtil.close(conn, ps, rs);
}
return classifyList;
}
/**
* 添加图书分类方法
*/
public boolean add(Classify classify) {
try {
conn = DBUtil.getConn();
String sql = "insert into classify (classify_id,classify_name) values(?,?)";
ps = conn.prepareStatement(sql);
ps.setInt(1, classify.getClassifyId());
ps.setString(2, classify.getClassifyName());
int result = ps.executeUpdate();
if (result > 0) {
return true;
} else {
return false;
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
return false;
} finally {
DBUtil.close(conn, ps, rs);
}
}
/**
*更新图书分类方法
*/
public boolean update(Classify classify) {
try {
conn = DBUtil.getConn();
String sql = "update classify set classify_name = ? where classify_id = '"+classify.getClassifyId() + "'";
ps = conn.prepareStatement(sql);
ps.setString(1, classify.getClassifyName());
int result = ps.executeUpdate();
if (result > 0) {
return true;
} else {
return false;
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
return false;
} finally {
DBUtil.close(conn, ps, rs);
}
}
}
4、上面主要写的就是,使用分层结构来实现增删改查,代码量占比比较大,写完这些代码,在下面的servlet界面调用就方便很多了,接下来就是写每种功能的jsp界面和servlet代码:
a、首先我们先来实现第一个界面的效果,第一个界面直接展示了图书信息,因此我们先让它执行查询的servlet,所以这里我们先把web.xml文件进行修改,修改后如下:
(注:找到下面的代码块,把原来的index.jsp修改为执行查询图书信息的servlet代码的路径)
(附:这里所有的servlet文件的路径都是文件名)例如:
b、好了,下面让我们来看查询图书信息的servlet代码:
package com.hnpi.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.hnpi.dao.BookDao;
import com.hnpi.dao.impl.BookDaoImpl;
import com.hnpi.model.Book;
public class SelectServlet extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
// 实例化接口
BookDao bookDao = new BookDaoImpl();
//获取BookDaoImpl()中的select()方法
List<Book> bookList = bookDao.select();
// 把bookList数组放到session
session.setAttribute("books", bookList);
//跳转到index.jsp界面,把数值展示出来
request.getRequestDispatcher("index.jsp").forward(request, response);
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
}
c、然后就是把查询后的结果展示到index.jsp界面,这里用到了<c:forEach></c:forEach>标签,这里要用到导包,我就直接放代码吧:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!--使用c:forEach标签,这句必须要有-->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>图书信息</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">
-->
<style type="text/css">
#a table,tr,th,td {
border: 1px #000 solid;
border-collapse: 0px;
text-align: center;
height: 30px;
background-color:rgba(255,204,51,0.5) ;
}
table {
width: 1000px;
font-size: 18px;
}
table tr:hover{
background-color: rgba(200,104,101,1);
}
a {
text-decoration: none; /* 去掉超链接的下划线 */
color: rgba(51, 153, 255, 1); /* 设置超链接的字体颜色 */
font-family: '微软雅黑'; /* 设置超链接的字体样式 */
display: block;
width: 100%;
height: 100%;
}
a:hover {
background-color: rgba(255,51,51,1);
background-repeat: no-repeat;
}
body{
background-image: url("WebContent/imgs/t5.jpg");
background-repeat: no-repeat;
}
</style>
</head>
<body>
<jsp:include page="lie_biao.jsp"></jsp:include>
<div style="width: 1000px; height: auto;margin-left: 100px">
<table id="a">
<tr>
<th>ID</th>
<th>图书名称</th>
<th>图书作者</th>
<th>图书编号</th>
<th>图书出版社</th>
<th>分类ID</th>
<th colspan="2">操作</th>
</tr>
<c:forEach items="${sessionScope.books}" var="bookInfo"
varStatus="status">
<tr>
<td>${bookInfo.id}</td>
<td>${bookInfo.bookName}</td>
<td>${bookInfo.bookAuthor}</td>
<td>${bookInfo.bookIsbn}</td>
<td>${bookInfo.bookPublish}</td>
<td>${bookInfo.classifyId}</td>
<th><a href="DelServlet?id=${bookInfo.id }"
onClick="return confirm('确定删除?');">删除</a>
</th>
<th><a
href="update_book.jsp?id=${bookInfo.id }&name=${bookInfo.bookName }&author=${bookInfo.bookAuthor }">更新</a>
</th>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
界面上,我用<jsp:include page=“lie_biao.jsp”></jsp:include>加了一个导航栏,导航栏代码如下:
<%@ 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>列表选择</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">
-->
<style type="text/css">
#div {
margin-left: 100px;
width: 1000px;
height: 50px;
float: left;
background-color: rgba(222, 183, 102, 1); ;
}
#dao li {
width: 200px;
height: 40px;
background-color: rgba(222, 183, 102, 1);
list-style: none;
float: left;
font-size: 24px;
text-align: center;
line-height: 40px;
margin-left: 25px;
margin-top: -10px;
}
#dao li a {
display: block;
width: 100%;
height: 100%;
text-decoration: none;
color: rgba(255, 255, 255, 1);
}
#dao li a:hover {
background-color: rgba(255, 255, 255, 1);
color: rgba(0, 0, 0, 1);
}
</style>
</head>
<body>
<div id="div">
<ul id="dao">
<li><a href="SelectServlet">查看图书信息</a></li>
<li><a href="add_book.jsp">添加图书信息</a></li>
<li><a href="ClassifyServlet">查看图书分类</a></li>
<li><a href="add_classify.jsp">添加图书分类</a></li>
</ul>
</div>
</body>
</html>
5、上面的代码打完就能做出第一个界面的效果了(背景图可以不要),接下来就是实现第一个界面上的删除和更新的操作了。
a、当点击删除后,如果删除成功,则执行一次查询操作,失败,就跳转到index.jsp界面,删除的servlet代码如下:
package com.hnpi.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hnpi.dao.BookDao;
import com.hnpi.dao.impl.BookDaoImpl;
import com.hnpi.model.Book;
public class DelServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
//获取index.jsp里面删除传过来的ID
String id = request.getParameter("id");
BookDao bookDao = new BookDaoImpl();
//判断如果true则跳转到SelectServlet界面,否则跳转到index.jsp界面
if(bookDao.delete(Integer.parseInt(id))){
response.sendRedirect("SelectServlet");
}else{
response.sendRedirect("index.jsp");
}
}
}
b、当点击更新时,跳转到更新界面update_book.jsp,填写内容后,如果成功执行查询操作,失败跳转到update_book.jsp界面,servlet代码如下:
package com.hnpi.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hnpi.dao.BookDao;
import com.hnpi.dao.impl.BookDaoImpl;
import com.hnpi.model.Book;
public class UpdateBook extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
BookDao bookDao = new BookDaoImpl();
Book book = new Book();
//获取update_book.jsp界面输入框的数值,然后设置到相对应的方法属性中
int id = Integer.parseInt(request.getParameter("id"));
book.setId(id);
book.setBookName(request.getParameter("name"));
book.setBookAuthor(request.getParameter("author"));
book.setBookIsbn(request.getParameter("isbn"));
book.setBookPublish(request.getParameter("publish"));
book.setClassifyId(Integer.parseInt(request.getParameter("classifyId")));
//判断如果true则跳转到SelectServlet界面,否则跳转到update_book.jsp界面
if(bookDao.update(book)){
response.sendRedirect("SelectServlet");
}else{
response.sendRedirect("update_book.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>更新图书</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" href="yangshi/css/book.css" type="text/css"></link>
<style type="text/css">
#tu {
background-image: url("WebContent/imgs/t4.jpg");
background-repeat: no-repeat;
width: 800px;
height: 600px;
margin-left: 240px;
background-size: 700px;
}
</style>
</head>
<body>
<%
//判断从index.jsp界面传过来的值是否为空,如果为空则不转换编码,跳转到SelectServlet界面,不为空则转换编码
if (!"".equals(request.getParameter("name"))
&& request.getParameter("name") != null
&& !"".equals(request.getParameter("author"))
&& request.getParameter("author") != null) {
String name = new String(request.getParameter("name").getBytes(
"ISO-8859-1"), "utf-8");
String author = new String(request.getParameter("author")
.getBytes("ISO-8859-1"), "utf-8");
session.setAttribute("name", name);
session.setAttribute("author", author);
} else {
response.sendRedirect("SelectServlet");
}
%>
<jsp:include page="lie_biao.jsp"></jsp:include>
<div style="float: left; margin-top: 320px">
<img src="WebContent/imgs/t1.jpg" style="width: 230px;"></img>
</div>
<div id="tu">
<form action="UpdateBook" method="post">
<div style="width: 100px; height: 130px;"></div>
<table id="tab">
<tr>
<td>
ID:
</td>
<td>
<input type="text" name="id" value="${param.id }" required="true"
onkeyup="this.value=this.value.replace(/\D/g,'')"
placeholder="请输入数字" />
</td>
</tr>
<tr>
<td>
图书名字:
</td>
<td>
<input type="text" name="name"
value="<%=session.getAttribute("name")%>" required="true" />
</td>
</tr>
<tr>
<td>
图书作者:
</td>
<td>
<input type="text" name="author"
value="<%=session.getAttribute("author")%>" required="true" />
</td>
</tr>
<tr>
<td>
图书编码:
</td>
<td>
<input type="text" name="isbn" required="true" />
</td>
</tr>
<tr>
<td>
图书出版社:
</td>
<td>
<input type="text" name="publish" required="true" />
</td>
</tr>
<tr>
<td>
分类ID:
</td>
<td>
<input type="text" name="classifyId" required="true"
onkeyup="this.value=this.value.replace(/\D/g,'')"
placeholder="请输入数字" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" value="提交" style="font-size: 20px" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
里面的css样式代码如下:
@CHARSET "UTF-8";
#tab {
font-size: 20px;
margin-left: 200px;
border: groove 2px green;
border-collapse: collapse;
border-style: dashed;
width: 400px;
}
#tab tr:hover {
background-color: rgba(100, 204, 101, 1);
}
#tab th {
text-align: right;
border: groove 1px green;
height: 50px;
}
#tab td {
border: groove 1px green;
height: 50px;
}
input {
width: 250px;
height: 40px;
}
6、上面代码,执行了图书信息的查删改操作,下面就是图书信息的添加了,添加的jsp界面如下:
附:这里面的外部css样式和更新的用的同一个
<%@ 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>添加图书</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">
-->
<link rel="stylesheet" href="yangshi/css/book.css" type="text/css"></link>
<style type="text/css">
#tu {
background-image: url("WebContent/imgs/t4.jpg");
background-repeat: no-repeat;
width: 800px;
height: 600px;
margin-left: 240px;
background-size: 700px;
}
</style>
</head>
<body>
<jsp:include page="lie_biao.jsp"></jsp:include>
<div style="float: left; margin-top: 320px">
<img src="WebContent/imgs/t1.jpg" style="width: 230px;"></img>
</div>
<div id="tu">
<form action="AddBookServlet" method="post">
<div style="width: 100px; height: 130px;"></div>
<table id="tab">
<tr>
<th>
ID:
</th>
<td>
<input type="text" name="id" required="true"
onkeyup="this.value=this.value.replace(/\D/g,'')"
placeholder="请输入数字" />
</td>
</tr>
<tr>
<th>
图书名字:
</th>
<td>
<input type="text" name="name" required="true" />
</td>
</tr>
<tr>
<th>
图书作者:
</th>
<td>
<input type="text" name="author" required="true" />
</td>
</tr>
<tr>
<th>
图书编码:
</th>
<td>
<input type="text" name="isbn" required="true" />
</td>
</tr>
<tr>
<th>
图书出版社:
</th>
<td>
<input type="text" name="publish" required="true" />
</td>
</tr>
<tr>
<th>
分类ID:
</th>
<td>
<input type="text" name="classifyId" required="true"
onkeyup="this.value=this.value.replace(/\D/g,'')"
placeholder="请输入数字" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" value="提交" style="font-size: 20px" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
二、以上就是图书信息的增删改查四个操作,代码量比较大,谢谢你的耐心浏览,下一篇是图书分类的增删改查,链接如下:图书信息管理的增删改查(三)