基于javaweb的JSP+Servlet图书借阅管理系统(java+jsp+bootstrap+jquery+servlet+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

032223062606

051323242606

460023442402

470023442402

480023442402

490023442402

500023442402

510023442402

基于javaweb的JSP+Servlet图书借阅管理系统(java+jsp+bootstrap+jquery+servlet+mysql)

项目介绍

本项目分为读者、管理员两种角色,登录验证码。 管理员主要功能包括: 图书管理:1)根据图书名称、作者、分类查询图书基本信息 2)添加、修改或删除图书信息

读者管理:1)根据账号、姓名、ID查询读者基本信息 2)添加、修改或删除读者信息

图书分类管理:1)查看图书分类信息,显示分类ID 2)添加、修改或删除图书分类

图书借阅信息:1)展示所有正在借阅的图书信息与读者信息 2)可以实现还书与延期功能

图书归还信息:1)展示所有已归还的图书的信息 2)记录图书出馆时间与归馆时间

管理员管理(需登录):1)仅最高管理员可以访问本页面 2)添加、修改或删除管理员信息

热门推荐:1)展示每一本书的借阅量,包括图书基本信息 2)可以查询书籍借阅量 最佳读者:展示每一位已知读者的借阅量,以及读者的基本信息

读者登录主要功能包括: 图书查询、借阅信息、借阅历史、热门推荐、最佳读者、问题反馈;

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;  5.数据库:MySql 5.7版本; 6.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目

技术栈

  1. 后端:Servlet 2. 前端:JSP+bootstrap+jQuery

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中util/DBUtil.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入http://localhost:8080/books/login.jsp 登录 注:tomcat中配置项目路径必须为/books 管理员用户名密码:101/101.123456 读者用户名密码:1816270150/wyz123456

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public LoginServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
// 获取账号和密码
String username = request.getParameter("username");
String password = request.getParameter("password");
String text = request.getParameter("code");
String code = (String) request.getSession().getAttribute("code");
AdminDao userdao = new AdminDao();
// 对账号和密码进行判断
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51


/**
* Servlet implementation class bdtimesServlet
*/
@WebServlet("/brtimesServlet")
public class brtimesServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public brtimesServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// doGet(request, response);
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
// 因为在管理员界面和读者界面都有查找功能,为了将查找的结果返回正确的页面,设置了tip,tip=1表示管理员界面
int tip = Integer.parseInt(request.getParameter("tip"));
String name = request.getParameter("name");
AdminDao admindao = new AdminDao();
ArrayList<AdminBean> data = admindao.getLikeList(name);
// 将获取的结果存入请求中
request.setAttribute("data", data);
String url = "";
// 转发不同的界面
if (tip == 1) {
url = response.encodeURL("admin_brtimes.jsp");
} else {
url = response.encodeURL("brtimes.jsp");
}
// 将请求转发
request.getRequestDispatcher(url).forward(request, response);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@WebServlet("/selectServlet")
public class selectServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public selectServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());

}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
// doGet(request, response);
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
// 因为在管理员界面和读者界面都有查找功能,为了将查找的结果返回正确的页面,设置了tip,tip=1表示管理员界面
int tip = Integer.parseInt(request.getParameter("tip"));
String name = request.getParameter("name");
BookDao bookdao = new BookDao();
ArrayList<BookBean> data = bookdao.getLikeList(name);
// 将获取的结果存入请求中
request.setAttribute("data", data);
String url = "";
// 转发不同的界面
if (tip == 1) {
url = response.encodeURL("admin_book.jsp");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

/**
* @see HttpServlet#HttpServlet()
*/
public AdminServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
// 设置编码类型
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
// 这里为了简单,设置了tip,用来区分是修改密码功能,还是修改个人资料的功能,tip=1为修改密码
int tip = Integer.parseInt(request.getParameter("tip"));
// 获取发起请求页面的文件名称,这个在对应的jsp里面的表单填写,修改完成后就可以直接返回对应的页面
String url = request.getParameter("url");
HttpSession session = request.getSession();
AdminBean adminbean = new AdminBean();
// 获取存到session的aid
String aid = (String) session.getAttribute("aid");
AdminDao admindao = new AdminDao();
// 通过aid获取到读者的信息
adminbean = admindao.get_AidInfo2(aid);
// 修改密码
if (tip == 1) {
// 获取到输入的旧密码,新密码
String password = request.getParameter("password");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
		// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
// doGet(request, response);
// 修改图书信息
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String card = request.getParameter("card");
String name = request.getParameter("name");
String type = request.getParameter("type");
String autho = request.getParameter("autho");
String press = request.getParameter("press");
int num = Integer.parseInt(request.getParameter("num"));
int bid = Integer.parseInt(request.getParameter("updatebid"));
BookDao bookdao = new BookDao();
bookdao.updateBook(bid, card, name, type, autho, press, num);
response.sendRedirect("/books/admin_book.jsp");
}

}
package com.rain.servlet;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");

BufferedImage bfi = new BufferedImage(80, 25, BufferedImage.TYPE_INT_RGB);
Graphics g = bfi.getGraphics();
g.fillRect(0, 0, 80, 25);

// 验证码字符范围
//char[] ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".toCharArray();
char[] ch = "0123456789".toCharArray();
Random r = new Random();
int index;
StringBuffer sb = new StringBuffer(); // 保存字符串
for (int i = 0; i < 4; i++) {
index = r.nextInt(ch.length);
g.setColor(new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
Font font = new Font("宋体", 30, 20);
g.setFont(font);
g.drawString(ch[index] + "", (i * 20) + 2, 23);
sb.append(ch[index]);
}

// 设置验证码中的干扰线
for (int i = 0; i < 6; i++) {
// 随机获取干扰线的起点和终点
int xstart = (int) (Math.random() * 80);
int ystart = (int) (Math.random() * 25);
int xend = (int) (Math.random() * 80);
int yend = (int) (Math.random() * 25);
g.setColor(interLine(1, 255));
g.drawLine(xstart, ystart, xend, yend);
}
HttpSession session = request.getSession(); // 保存到session
session.setAttribute("code", sb.toString());
ImageIO.write(bfi, "JPG", response.getOutputStream()); // 写到输出流
}

private static Color interLine(int Low, int High) {
if (Low > 255)
Low = 255;
if (High > 255)
High = 255;
if (Low < 0)
Low = 0;
if (High < 0)
High = 0;
int interval = High - Low;
int r = Low + (int) (Math.random() * interval);
int g = Low + (int) (Math.random() * interval);
int b = Low + (int) (Math.random() * interval);


项目链接:
https://javayms.github.io?id=151122522008200oc
https://javayms.pages.dev?id=151122522008200oc