图书添加
创建Web项目,通过JDBC实现图书信息添加功能。 (1)在数据库中创建图书信息表tb-books (2)创建名称为Book的类,用于封装图书对象信息。关键代码如下: package com.lyq.bean; public cla Book { // 编号
private int id; // 图书名称
private String name; // 价格
private double price; // 数量
private int bookCount; // 作者
private String author; public int getId() {
return id; } public void setId(int id) {
this.id = id; } public String getName() {
return name; } public void setName(String name) {
this.name = name; } public double getPrice() {
return price; } public void setPrice(double price) {
this.price = price; } public int getBookCount() {
return bookCount; } public void setBookCount(int bookCount) {
this.bookCount = bookCount; } public String getAuthor() {
return author; } public void setAuthor(String author) {
this.author = author; } } (3)创建index.jsp页面,用于放置添加图书信息所需的表单,该表单提交到AddBook.jsp页面进行处理。关键代码如下: <%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%> 添加图书信息 <script type=\"text/javascript\"> function check(form){
with(form){
if(name.value == \"\"){
alert(\"图书名称不能为空\");
return false;
}
if(price.value == \"\"){
alert(\"价格不能为空\");
return false;
}
if(author.value == \"\"){
alert(\"作者不能为空\");
return false;
}
return true;
} } </script>
添加图书信息
图书名称:
价
格:
数
量:
作
者: