IDEA+Java+Servlet+JSP+Mysql实现Web图书管理系统【建议收藏】(下)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: IDEA+Java+Servlet+JSP+Mysql实现Web图书管理系统【建议收藏】

三、部分代码


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+JSP实现学生图书管理系统


Java+JSP实现学生信息管理系统


Java+JSP实现用户信息管理系统


Java+Servlet+JSP实现航空订票系统


Java+Servlet+JSP实现新闻发布系统


Java+Servlet+JSP实现停车场管理系统


Java+Servlet+JSP实现学生信息管理系统


Java+Servlet+JSP实现学生选课管理系统


Java+Servlet+JSP实现学生成绩管理系统-1


Java+Servlet+JSP实现学生成绩管理系统-2


Java+Servlet+JSP实现宠物诊所管理系统


Java+SSM+JSP实现网上考试系统


Java+SSH+JSP实现在线考试系统


Java+SSH+JSP实现医院在线挂号系统


Java+Springboot+Mybatis+Bootstrap+Maven实现网上商城系统


2.JavaSwing系统系列实现


Java+Swing实现斗地主游戏


Java+Swing实现图书管理系统


Java+Swing实现医院管理系统


Java+Swing实现考试管理系统


Java+Swing实现仓库管理系统-1


Java+Swing实现仓库管理系统-2


Java+Swing实现自助取款机系统


Java+Swing实现通讯录管理系统


Java+Swing实现停车场管理系统


Java+Swing实现学生信息管理系统


Java+Swing实现学生宿舍管理系统


Java+Swing实现学生选课管理系统


Java+Swing实现学生成绩管理系统


Java+Swing实现学校教材管理系统


Java+Swing实现学校教务管理系统


Java+Swing实现企业人事管理系统


Java+Swing实现电子相册管理系统


Java+Swing实现超市管理系统-TXT存储数据


Java+Swing实现自助取款机系统-TXT存储数据


Java+Swing实现宠物商店管理系统-TXT存储数据


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
18天前
|
Java
学校教师管理系统【JSP+Servlet+JavaBean】(Java课设)
学校教师管理系统【JSP+Servlet+JavaBean】(Java课设)
19 1
|
18天前
|
Java
人事管理系统【JSP+Servlet+JavaBean】(Java课设)
人事管理系统【JSP+Servlet+JavaBean】(Java课设)
16 0
|
22天前
|
缓存 NoSQL 关系型数据库
在Python Web开发过程中:数据库与缓存,MySQL和NoSQL数据库的主要差异是什么?
MySQL是关系型DB,依赖预定义的表格结构,适合结构化数据和复杂查询,但扩展性有限。NoSQL提供灵活的非结构化数据存储(如JSON),无统一查询语言,但能横向扩展,适用于大规模、高并发场景。选择取决于应用需求和扩展策略。
112 1
|
30天前
使用Servlet上传多张图片——前台页面层(Index.jsp)
使用Servlet上传多张图片——前台页面层(Index.jsp)
12 0
|
3月前
|
Java
JAVA实现图书管理系统(思路,和完整代码)
JAVA实现图书管理系统(思路,和完整代码)
135 0
|
2月前
|
Java
IDEA Error:java: Compilation failed: internal java compiler error 解决办法
IDEA Error:java: Compilation failed: internal java compiler error 解决办法
|
4天前
|
Web App开发 Java 应用服务中间件
【Java Web】在 IDEA 中部署 Tomcat
【Java Web】在 IDEA 中部署 Tomcat
20 0
|
4天前
|
PHP
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
|
7天前
|
Java 应用服务中间件 Maven
使用IDEA搭建SpringMVC环境,Maven导入了依赖,但是运行报错 java.lang.ClassNotFoundException
使用IDEA搭建SpringMVC环境,Maven导入了依赖,但是运行报错 java.lang.ClassNotFoundException
8 1
|
18天前
|
Java
排课系统【JSP+Servlet+JavaBean】(Java课设)
排课系统【JSP+Servlet+JavaBean】(Java课设)
7 0