IDEA+Java+Servlet+JSP+Mysql实现Web图书管理系统
Posted 水坚石青
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA+Java+Servlet+JSP+Mysql实现Web图书管理系统相关的知识,希望对你有一定的参考价值。
目录
JavaWeb系统系列实现
Java+Springboot+Mybatis+Bootstrap+Maven实现网上商城系统
一、系统介绍
1.开发环境
开发工具:IDEA2018.2
JDK版本:jdk1.8
mysql版本:8.0.13
2.技术选型
后端:Java+Servlet进行开发。
前端:JSP+html+CSS。
3.系统功能
1.登录系统
2.图书的增删改查
3.借书与还书
4.图书进出记录
5.用户管理
6.注销
4.数据库
/*
Navicat Premium Data Transfer
Source Server : MySQL
Source Server Type : MySQL
Source Server Version : 80013
Source Host : 127.0.0.1:3306
Source Schema : servlet_library
Target Server Type : MySQL
Target Server Version : 80013
File Encoding : 65001
Date: 21/08/2021 22:14:51
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for book
-- ----------------------------
DROP TABLE IF EXISTS `book`;
CREATE TABLE `book` (
`id` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '书本ID',
`bookname` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '书本名称',
`author` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '书本作者',
`publisher` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '出版社',
`price` int(11) NULL DEFAULT NULL COMMENT '书本价格',
`category` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '书本类目',
`store` int(11) NULL DEFAULT NULL,
`bookdesc` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`location` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '书籍数据库' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of book
-- ----------------------------
INSERT INTO `book` VALUES ('000001', 'Java核心技术', '凯 S. 霍斯特曼', '机械工业出版社', 130, '编程类', 200, '《JAVA核心技术》(第8版)是2011年电子工业出版社出版的图书,作者是昊斯特曼、Gary Cornell。本书针对JavaSE6平台进行了全面更新,囊括了Java平台标准版(JavaSE/J2SE)的全部基础知识,提供了大量完整且具有实际意义的应用实例。', '3');
INSERT INTO `book` VALUES ('000003', '算法竞赛入门经典', '刘汝佳', '清华大学出版社', 50, '编程类', 15, '《JAVA核心技术》(第8版)是2011年电子工业出版社出版的图书,作者是昊斯特曼、Gary Cornell。本书针对JavaSE6平台进行了全面更新,囊括了Java平台标准版(JavaSE/J2SE)的全部基础知识,提供了大量完整且具有实际意义的应用实例。', '3');
INSERT INTO `book` VALUES ('000004', '概率论与数理统计', '盛骤 谢式千 潘承毅', '高等教育出版社', 38, '数学类', 15, '《JAVA核心技术》(第8版)是2011年电子工业出版社出版的图书,作者是昊斯特曼、Gary Cornell。本书针对JavaSE6平台进行了全面更新,囊括了Java平台标准版(JavaSE/J2SE)的全部基础知识,提供了大量完整且具有实际意义的应用实例。', '1');
INSERT INTO `book` VALUES ('000005', '数据结构(C语言版)', '严蔚敏 吴伟民', '清华大学出版社', 29, '编程类', 8, '《JAVA核心技术》(第8版)是2011年电子工业出版社出版的图书,作者是昊斯特曼、Gary Cornell。本书针对JavaSE6平台进行了全面更新,囊括了Java平台标准版(JavaSE/J2SE)的全部基础知识,提供了大量完整且具有实际意义的应用实例。', '3');
-- ----------------------------
-- Table structure for iolog
-- ----------------------------
DROP TABLE IF EXISTS `iolog`;
CREATE TABLE `iolog` (
`bookid` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`readerid` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`service` int(11) NULL DEFAULT NULL,
`borrowtime` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`borrowday` int(11) NULL DEFAULT NULL,
`complete` int(11) NULL DEFAULT NULL,
PRIMARY KEY (`borrowtime`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of iolog
-- ----------------------------
INSERT INTO `iolog` VALUES ('000001', '1', -1, '2021年08月21日 21时38分10秒', 7, 1);
INSERT INTO `iolog` VALUES ('000001', '1', 1, '2021年08月21日 21时38分20秒', NULL, 1);
-- ----------------------------
-- Table structure for reader
-- ----------------------------
DROP TABLE IF EXISTS `reader`;
CREATE TABLE `reader` (
`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '读者用户名',
`password` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '读者密码',
`name` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '读者姓名',
`sex` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '读者性别',
`status` int(11) NULL DEFAULT NULL COMMENT '读者状态(1.正常 -1.黑名单)',
`mail` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '读者邮箱',
`tel` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '读者电话',
`grade` int(11) NULL DEFAULT -1 COMMENT '读者年级',
`classnum` int(11) NULL DEFAULT -1 COMMENT '读者班级',
PRIMARY KEY (`username`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '读者表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of reader
-- ----------------------------
INSERT INTO `reader` VALUES ('1', '123456', '测试', '测试', 1, '测试', '测试', 1, 1);
-- ----------------------------
-- Table structure for tempadd
-- ----------------------------
DROP TABLE IF EXISTS `tempadd`;
CREATE TABLE `tempadd` (
`id` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`bookname` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '书本名称',
`author` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '书本作者',
`publisher` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '出版社',
`price` int(11) NULL DEFAULT NULL COMMENT '书本价格',
`category` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '书本类目',
`store` int(11) NULL DEFAULT NULL,
`bookdesc` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`location` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of tempadd
-- ----------------------------
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`user` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
`password` varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户密码',
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户真实姓名',
`sex` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户性别',
`department` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户部门',
`tel` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户电话',
PRIMARY KEY (`user`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('admin', 'admin', '管理员', '男', '图书馆', '12345678901');
SET FOREIGN_KEY_CHECKS = 1;
5.工程截图
二、系统展示
1.登录系统
2.主页面
3.图书列表
4.图书详情
5.编辑删除
6.添加图书
7.图书借阅
8.图书归还
9.借阅记录
10.用户管理
三、部分代码
BookAction
package Action;
import Dao.BookDao;
import Entity.Book;
import Entity.User;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
public class BookAction extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String action = request.getParameter("action");
if (action.equals("getall")) {
this.getAll(request, response);
} else if (action.equals("addtemp")) {
this.addtemp(request, response);
} else if (action.equals("gettemp")) {
this.gettemp(request, response);
} else if (action.equals("confirm")) {
this.confirm(request, response);
} else if (action.equals("querybookbyid")) {
this.QueryBookById(request, response);
} else if (action.equals("DeleteById")) {
this.DeleteById(request, response);
} else if (action.equals("EditDone")) {
this.EditDone(request, response);
}
}
private void getAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
BookDao bdao = new BookDao();
ArrayList<Book> bookArrayList = bdao.getAllBook();
HttpSession session = request.getSession();
session.setAttribute("allbooklist", bookArrayList);
request.getRequestDispatcher("/book-list.jsp").forward(request, response);
}
private void addtemp(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String next = request.getParameter("over");
BookDao bdao = new BookDao();
Book book = new Book();
if (!request.getParameter("bookid").equals(""))
book.setId(request.getParameter("bookid"));
if (!request.getParameter("bookname").equals(""))
book.setName(request.getParameter("bookname"));
if (!request.getParameter("bookauthor").equals(""))
book.setAuthor(request.getParameter("bookauthor"));
if (!request.getParameter("bookpublisher").equals(""))
book.setPublisher(request.getParameter("bookpublisher"));
if (!request.getParameter("bookcategory").equals(""))
book.setCategory(request.getParameter("bookcategory"));
if (!request.getParameter("bookprice").trim().equals(""))
book.setPrice(Integer.parseInt(request.getParameter("bookprice")));
if (!request.getParameter("bookstore").trim().equals(""))
book.setStore(Integer.parseInt(request.getParameter("bookstore")));
if (!request.getParameter("booklocation").equals(""))
book.setLocation(request.getParameter("booklocation"));
if (!request.getParameter("bookdesc").equals(""))
book.setDesc(request.getParameter("bookdesc"));
if (!request.getParameter("bookid").equals(""))
bdao.addtemp(book);
if (next.equals("0"))
request.getRequestDispatcher("/add-book.jsp").forward(request, response);
else
this.gettemp(request, response);
}
private void gettemp(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
BookDao bdao = new BookDao();
ArrayList<Book> addbooklist = bdao.getadd();
HttpSession session = request.getSession();
session.setAttribute("addbooklist", addbooklist);
request.getRequestDispatcher("/add-confirm.jsp").forward(request, response);
}
private void confirm(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
BookDao bdao = new BookDao();
bdao.confirm();
this.getAll(request, response);
}
private void QueryBookById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
BookDao bdao = new BookDao();
String id = request.getParameter("id");
String next = request.getParameter("next");
Book book = bdao.QueryBookById(id);
HttpSession session = request.getSession();
session.setAttribute("resultbook", book);
PrintWriter out = response.getWriter();
if (next.equals("check"))
request.getRequestDispatcher("/detail.jsp").forward(request, response);
else if (next.equals("edit"))
request.getRequestDispatcher("/edit-book.jsp").forward(request, response);
else if (next.equals("borrowcheck")) {
out.write(book.getName() + "||" + book.getAuthor() + "||" + book.getPublisher() + "||" + book.getRemain());
}
}
private void DeleteById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
BookDao bdao = new BookDao();
String id = request.getParameter("id");
bdao.DeleteById(id);
this.getAll(request, response);
}
private void EditDone(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
BookDao bdao = new BookDao();
Book book = new Book();
if (!request.getParameter("id").equals(""))
book.setId(request.getParameter("id"));
if (!request.getParameter("name").equals(""))
book.setName(request.getParameter("name"));
if (!request.getParameter("author").equals(""))
book.setAuthor(request.getParameter("author"));
if (!request.getParameter("publisher").equals(""))
book.setPublisher(request.getParameter("publisher"));
if (!request.getParameter("category").equals(""))
book.setCategory(request.getParameter("category"));
if (!request.getParameter("price").trim().equals(""))
book.setPrice(Integer.parseInt(request.getParameter("price")));
if (!request.getParameter("store").trim().equals(""))
book.setStore(Integer.parseInt(request.getParameter("store")));
if (!request.getParameter("location").equals(""))
book.setLocation(request.getParameter("location"));
if (!request.getParameter("desc").equals(""))
book.setDesc(request.getParameter("desc"));
if (!request.getParameter("id").equals(""))
bdao.addtemp(book);
bdao.EditDone(book);
request.getRequestDispatcher("BookAction?action=querybookbyid&id=<%=b.getId()%>&next=check").forward(request, response);
}
}
IOAction
package Action;
import Dao.IODao;
import Entity.Log;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class IOAction extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
if (action.equals("borrow")) {
this.borrow(request, response);
} else if (action.equals("getlog")) {
this.getlog(request, response);
} else if (action.equals("return")) {
this.ReturnBook(request, response);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
protected void borrow(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
IODao ioDao = new IODao();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
Date date = new Date();
String time = sdf.format(date);
String readerid = request.getParameter("readerid");
String bookid = request.getParameter("bookid");
int borrowday = Integer.parseInt(request.getParameter("borrowday"));
ioDao.borrow(bookid, readerid, time, borrowday);
this.getlog(request, response);
}
protected void getlog(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
IODao ioDao = new IODao();
ArrayList<Log> loglist = ioDao.getLogList();
HttpSession session = request.getSession();
session.setAttribute("loglist", loglist);
request.getRequestDispatcher("/io-log.jsp").forward(request, response);
}
protected void ReturnBook(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
IODao ioDao = new IODao();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
Date date = new Date();
String Returntime = sdf.format(date);
String bookid = request.getParameter("bookid");
String readerId = request.getParameter("ReaderId");
String borrowtime = request.getParameter("borrowtime");
ioDao.ReturnBook(bookid, readerId, borrowtime, Returntime);
this.getlog(request, response);
}
}
LoginAction
package Action;
import Dao.UserDao;
import Entity.User;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
public class LoginAction extends HttpServlet {
UserDao udao = new UserDao();
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
if (action.equals("login")) {
this.login(request, response);
} else if (action.equals("logout")) {
this.logout(request, response);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
private void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = null;
String password = null;
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
username = request.getParameter("username");
password = request.getParameter("password");
User user = new User();
user.setUsername(username);
user.setPassword(password);
String result = udao.login(user);
if (result.equals("true")) {
session.setAttribute("adminname", user.getName());
request.getRequestDispatcher("/main.jsp").forward(request, response);
} else {
out.write(result);
}
}
private void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
session.setMaxInactiveInterval(1);
response.sendRedirect("/index.jsp");
}
}
ReaderAction
package Action;
/**
* 读者管理
*/
import Dao.IODao;
import Dao.ReaderDao;
import Entity.Log;
import Entity.Reader;
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 java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
public class ReaderAction extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
if (action.equals("QueryReaderById")) {
this.QueryReaderById(request, response);
} else if (action.equals("GetBorrowListById")) {
this.GetBorrowListById(request, response);
} else if (action.equals("GetAllReader")) {
this.GetAllReader(request, response);
} else if (action.equals("SetBlackList")) {
this.SetBlackList(request, response);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void QueryReaderById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String readerid = request.getParameter("readerid");
ReaderDao readerDao = new ReaderDao();
Reader reader = readerDao.QueryReaderById(readerid);
String stauts = (reader.getStatus() == 1) ? "正常" : "异常";
String callback = reader.getName() + "||" + reader.getGrade() + "年级" + reader.getClassnum() + "班||" + stauts + "||" + reader.getBorrow();
PrintWriter out = response.getWriter();
out.write(callback);
}
protected void GetBorrowListById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("readerid");
IODao ioDao = new IODao();
ArrayList<Log> loglist = ioDao.QueryBorrowNumByReaderid(id);
HttpSession session = request.getSession();
session.setAttribute("loglist", loglist);
request.getRequestDispatcher("/borrow-list.jsp").forward(request, response);
}
protected void GetAllReader(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ReaderDao readerDao = new ReaderDao();
ArrayList<Reader> readerlist = readerDao.GetAllReader();
HttpSession session = request.getSession();
session.setAttribute("readerlist", readerlist);
request.getRequestDispatcher("/reader-list.jsp").forward(request, response);
}
protected void SetBlackList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("id");
String edit = request.getParameter("edit");
ReaderDao readerDao = new ReaderDao();
if (edit.equals("设置为正常")) {
readerDao.SetBlackList(username, true);
} else {
readerDao.SetBlackList(username, false);
}
this.GetAllReader(request, response);
}
}
四、其他
1.其他系统实现
1.JavaWeb系统系列实现
Java+Springboot+Mybatis+Bootstrap+Maven实现网上商城系统
2.JavaSwing系统系列实现
2.获取源码
点击以下链接获取源码,数据库文件在sql文件下面。
3.运行项目
请点击以下链接,部署你的项目。
4.备注
如有侵权请联系我删除。
5.支持博主
如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!想要获取其他资源可关注左侧微信公众号获取!
以上是关于IDEA+Java+Servlet+JSP+Mysql实现Web图书管理系统的主要内容,如果未能解决你的问题,请参考以下文章
IDEA+Java+Servlet+JSP+Mysql实现新闻发布系统
IDEA+Java+Servlet+JSP+Mysql实现Web图书管理系统
IDEA+Java+Servlet+JSP+Bootstrap+Mysql实现Web学生成绩管理系统
IDEA+Java+Servlet+JSP+Bootstrap+Mysql实现Web学生成绩管理系统