简单的图书管理系统
通过数据源和DAO对象访问数据库。其中JavaBeans实现模型,访问数据库,Servlet实现控制器,JSP页面实现视图。
• 模型包括2个JavaBean:BookBean用于存放图书信息,BookDAO用于访问数据库。
• 控制器包括2个Servlet:BookQueryServlet根据请求参数查询图书信息、BookInsertServlet用来向数据库中插入数据。
• 视图包括4个JSP页面:bookQuery.jsp显示查询页面、bookInsert.jsp显示插入页面、display.jsp显示查询结果页面和errorPage.jsp显示错误页面。
context.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
auth="Container"
driverClassName="com.mysql.cj.jdbc.Driver"
maxIdle="30"
maxTotal="50"
maxWaitMillis="-1"
name="jdbc/book"
username="rotdas"
password="dasdash"
type="javax.sql.DataSource"
url="jdbc:mysql://127.0.0.1:3306/book?serverTimezone=UTC"/>
</Context>
源代码
BookBean代码
public class BookBean implements Serializable {
private String bookid = null;
private String title = null;
private String author = null;
private String publisher = null;
private float price = 0.0F;
public BookBean(){
}
public BookBean(String bookId, String author,
String title, String publisher, float price) {
this.bookid = bookId;
this.title = title;
this.author = author;
this.publisher = publisher;
this.price = price;
}
public String getBookid() {
return this.bookid; }
public String getTitle() {
return title; }
public String getAuthor() {
return this.author; }
public float getPrice() {
return price; }
public String getPublisher () {
return publisher; }
public void setBookid(String bookid){
this.bookid=bookid; }
public void setTitle(String title){
this.title=title; }
public void setAuthor(String author){
this. author = author; }
public void setPrice(float price){
this.price=price; }
public void setPublisher (String publisher){
this