跨境派

跨境派

跨境派,专注跨境行业新闻资讯、跨境电商知识分享!

当前位置:首页 > 卖家故事 > JavaWeb期末大作业——图书管理系统

JavaWeb期末大作业——图书管理系统

时间:2024-03-26 15:50:49 来源:网络cs 作者:璐璐 栏目:卖家故事 阅读:

标签: 图书  管理  系统  作业 
阅读本书更多章节>>>>

目录

一、系统介绍

1.开发的环境

2.本系统实现的功能

3.数据库用到的表

4.工程截图

二、系统展示

1.登录页面

2.注册页面

3.管理员主页面

​编辑 

4. 用户主页面

 5.图书管理页面(管理员)

6.读者管理页面(管理员)

​编辑 7.图书分类管理页面(管理员)

8.图书借阅管理页面(管理员)

 9.图书归还信息页面(管理员)

10.图书日志查询(管理员)

​编辑

11. 图书借阅页面(用户)

12.还书页面(用户)

​编辑 13.借阅历史页面(用户)

 三、部分代码展示

AdminDao.java

 LoginServlet.java

 RegisterServlet.java

 BookBean.java

 AdminServlet.java 

四、源码

点击以下链接(内含数据库文件——books.sql):

五、备注 

六、祝福


一、系统介绍

1.开发的环境

开发工具:eclipse 2022

JDK版本:1.8

数据库:MySQL 5.5

数据库管理软件:Navicat 15.0.27

服务器:apach-tomcat-9.0.68

2.本系统实现的功能

管理员功能:登陆系统、用户信息的增删改查、图书的增删改查、图书分类的增删改查、图书日志查询、图书归还。

用户功能:登陆系统、查阅图书、借阅和归还图书、查询借阅记录

3.数据库用到的表

admin、book、booktype、history

4.工程截图

 

二、系统展示

1.登录页面

2.注册页面

 

3.管理员主页面

 

4. 用户主页面

 5.图书管理页面(管理员)

6.读者管理页面(管理员)

 7.图书分类管理页面(管理员)

8.图书借阅管理页面(管理员)

 9.图书归还信息页面(管理员)

10.图书日志查询(管理员)

11. 图书借阅页面(用户)

12.还书页面(用户)

 13.借阅历史页面(用户)

 三、部分代码展示

AdminDao.java

package com.hry.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import com.hry.bean.AdminBean;import com.hry.dbUtils.DbUtil;public class AdminDao {/** * 登录验证功能,传入用户名和密码,在数据库中查找,如果找到了,返回true,没找到则返回false * username、password */public boolean Login_verify(String username,String password){//连接数据库DbUtil dbUtil=new DbUtil();Connection conn = dbUtil.getConn();//sql语句String sql = "select * from admin where username='"+username+"' and password='"+password+"'";PreparedStatement stm = null;ResultSet rs = null;try {//预编译SQL,减少sql执行stm = conn.prepareStatement(sql);rs = stm.executeQuery();if(rs.next()){return true;}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally {DbUtil.CloseDB(rs, stm, conn);}return false;}/** * 注册账号的函数,传入账号,密码,姓名,邮箱,手机号,借阅天数,可借阅数 *  username,  password,  name,  email,  phone, lend_num, max_num */public void Register(String username, String password, String name, String email, String phone,int lend_num,int max_num) {// TODO Auto-generated method stub//连接数据库        DbUtil dbUtil=new DbUtil();Connection conn = dbUtil.getConn();//sql语句String sql = "insert  into admin(status,username,password,name,email,phone,lend_num,max_num) values(?,?,?,?,?,?,?,?)";int rs = 0;PreparedStatement stm = null;try {//预编译SQL,减少sql执行stm = conn.prepareStatement(sql);//传参stm.setInt(1, 1);stm.setString(2, username);stm.setString(3, password);stm.setString(4, name);stm.setString(5, email);stm.setString(6, phone);stm.setInt(7, lend_num);//借阅天数stm.setInt(8, max_num);//可借阅数//执行更新rs = stm.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}/** * 根据传入的账号,密码,来查找对应的读者信息,返回一个AdminBean类型, *  */public AdminBean getAdminInfo(String username, String password) {// TODO Auto-generated method stubAdminBean adminbean = new AdminBean();DbUtil dbUtil=new DbUtil();Connection conn = dbUtil.getConn();String sql = "select * from admin where username='"+username+"' and password='"+password+"'";PreparedStatement stm = null;ResultSet rs = null;try {//预编译SQL,减少sql执行stm = conn.prepareStatement(sql);//执行查询rs = stm.executeQuery();if(rs.next()){//传参adminbean.setAid(rs.getInt("aid"));adminbean.setUsername(rs.getString("username"));adminbean.setName(rs.getString("name"));adminbean.setPassword(rs.getString("password"));adminbean.setEmail(rs.getString("email"));adminbean.setPhone(rs.getString("phone"));adminbean.setStatus(rs.getInt("status"));adminbean.setLend_num(rs.getInt("lend_num"));adminbean.setMax_num(rs.getInt("max_num"));}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally {DbUtil.CloseDB(rs, stm, conn);}return adminbean;}/** * 获取全部用户的信息,其中sql语句中的status=1,表示只查找读者(1),不显示管理员(2)的 *  */public ArrayList<AdminBean> get_ListInfo(){ArrayList<AdminBean> tag_Array = new ArrayList<AdminBean>();Connection conn = DbUtil.getConn();String sql = "select * from admin where status=1";PreparedStatement stm = null;ResultSet rs = null;try {stm = conn.prepareStatement(sql);rs = stm.executeQuery();while(rs.next()){AdminBean adminbean = new AdminBean();adminbean.setAid(rs.getInt("aid"));adminbean.setUsername(rs.getString("username"));adminbean.setName(rs.getString("name"));adminbean.setPassword(rs.getString("password"));adminbean.setEmail(rs.getString("email"));adminbean.setPhone(rs.getString("phone"));adminbean.setStatus(rs.getInt("status"));adminbean.setLend_num(rs.getInt("lend_num"));adminbean.setMax_num(rs.getInt("max_num"));tag_Array.add(adminbean);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally {DbUtil.CloseDB(rs, stm, conn);}return tag_Array;}/** * 根据传入的aid图书号,查找到对应的读者的全部信息,返回一个AdminBean类型的数据,与上一个相似,只是aid的类型为String, *  */public AdminBean get_AidInfo2(String aid){AdminBean adminbean = new AdminBean();DbUtil dbUtil=new DbUtil();Connection conn = dbUtil.getConn();String sql = "select * from admin where aid="+aid;PreparedStatement stm = null;ResultSet rs = null;try {stm = conn.prepareStatement(sql);rs = stm.executeQuery();if(rs.next()){adminbean.setAid(rs.getInt("aid"));adminbean.setUsername(rs.getString("username"));adminbean.setName(rs.getString("name"));adminbean.setPassword(rs.getString("password"));adminbean.setEmail(rs.getString("email"));adminbean.setPhone(rs.getString("phone"));adminbean.setStatus(rs.getInt("status"));adminbean.setLend_num(rs.getInt("lend_num"));adminbean.setMax_num(rs.getInt("max_num"));}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally {DbUtil.CloseDB(rs, stm, conn);}return adminbean;}/** * 修改读者的信息 */public void updateUser(int aid, String username, String password, String name, String email, String phone,int lend_num, int max_num) {// TODO Auto-generated method stubDbUtil dbUtil=new DbUtil();Connection conn = dbUtil.getConn();String sql = "update admin set username=?,name=?,email=?,phone=?,password=?,lend_num=?,max_num=? where aid=?";PreparedStatement stm = null;try {stm = conn.prepareStatement(sql);stm.setString(1, username);stm.setString(2, name);stm.setString(3, email);stm.setString(4, phone);stm.setString(5, password);stm.setInt(6, lend_num);stm.setInt(7, max_num);stm.setInt(8, aid);stm.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}/** * 删除用户的信息,根据传入的aid作为条件 *  */public void deleteUser(int aid) {// TODO Auto-generated method stubDbUtil dbUtil=new DbUtil();Connection conn = dbUtil.getConn();String sql = "delete from admin where aid=?";PreparedStatement stm = null;try {stm = conn.prepareStatement(sql);stm.setInt(1, aid);stm.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

 LoginServlet.java

package com.hry.servlet;import java.io.IOException;import java.io.PrintWriter;import java.sql.Connection;import java.sql.SQLException;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 com.hry.bean.AdminBean;import com.hry.dao.AdminDao;/** * Servlet implementation class LoginServlet */@WebServlet("/LoginServlet")public class LoginServlet extends HttpServlet {private static final long serialVersionUID = 1L;AdminDao userdao = new AdminDao(); AdminDao admindao = new AdminDao();    /**     * @see HttpServlet#HttpServlet()     */    public LoginServlet() {        super();        // TODO Auto-generated constructor stub    }   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//登录的判断//编码格式request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");//获取账号和密码//PrintWriter out = response.getWriter();String username = request.getParameter("username");String password = request.getParameter("password");System.out.println(username);//对账号和密码进行判断boolean result = userdao.Login_verify(username, password);System.out.println(result);HttpSession session = request.getSession();//判断输入正确if(result){AdminBean adminbean = new AdminBean();//更加账号和密码查找出读者的信息adminbean = admindao.getAdminInfo(username,password);//将aid存入session中session.setAttribute("aid", ""+adminbean.getAid());//设置session的失效时间session.setMaxInactiveInterval(6000);//根据status的值来判断是管理员,还是读者,status=1为读者System.out.println(adminbean.getStatus());if(adminbean.getStatus()==1){response.sendRedirect("index2.jsp");}else{response.sendRedirect("admin.jsp");}}else{//没有找到对应的账号和密码,返回重新登录session.setAttribute("state", "密码错误");response.sendRedirect("login.jsp");}}}

 RegisterServlet.java

package com.hry.servlet;import java.io.IOException;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 com.hry.bean.AdminBean;import com.hry.dao.AdminDao;/** * Servlet implementation class RegisterServlet */@WebServlet("/RegisterServlet")public class RegisterServlet extends HttpServlet {private static final long serialVersionUID = 1L;           public RegisterServlet() {        super();        // TODO Auto-generated constructor stub    }/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}/** * @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");//获取注册信息AdminDao userdao = new AdminDao();String username = request.getParameter("username");String password = request.getParameter("password");String name = request.getParameter("name");String email = request.getParameter("email");String phone = request.getParameter("phone");System.out.println(username);//默认设置最大借阅数和借阅天数int lend_num = 30;int max_num = 5;//将注册信息存入数据库,再返回登录userdao.Register(username,password,name,email,phone,lend_num,max_num);        response.sendRedirect("login.jsp");}}

 BookBean.java

package com.hry.bean;public class BookBean {/** * 图书的数据表的bean */private int bid;//图书idprivate String name;//图书名称private String card;//图书号private String autho;//作者private int num;//图书数量private String type;//图书的分类private String press;//出版社public int getBid() {return bid;}public void setBid(int bid) {this.bid = bid;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getCard() {return card;}public void setCard(String card) {this.card = card;}public String getAutho() {return autho;}public void setAutho(String autho) {this.autho = autho;}public int getNum() {return num;}public void setNum(int num) {this.num = num;}public String getType() {return type;}public void setType(String type) {this.type = type;}public String getPress() {return press;}public void setPress(String press) {this.press = press;}}

 AdminServlet.java 

package com.hry.servlet;import java.io.IOException;import java.io.PrintWriter;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 com.hry.bean.AdminBean;import com.hry.dao.AdminDao;import com.hry.dao.BookDao;/** * Servlet implementation class AdminServlet */@WebServlet("/AdminServlet")public class AdminServlet extends HttpServlet {private static final long serialVersionUID = 1L;           public AdminServlet() {        super();        // TODO Auto-generated constructor stub    }protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//PrintWriter:输出流,为异常处理PrintWriter out = response.getWriter();//设置编码类型request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");BookDao bookdao = new BookDao();//这里为了简单,设置了tip,用来区分是修改密码功能,还是修改个人资料的功能,tip=1为修改密码int tip = Integer.parseInt(request.getParameter("tip"));//获取发起请求页面的文件名称,这个在对应的jsp里面的表单填写,修改完成后就可以直接返回对应的页面String url = request.getParameter("url");System.out.println(url);HttpSession session = request.getSession();AdminBean adminbean = new AdminBean();//获取存到session的aidString aid = (String) session.getAttribute("aid");AdminDao admindao = new AdminDao();//通过aid获取到读者的信息adminbean = admindao.get_AidInfo2(aid);//修改密码if (tip==1) {//获取到输入的旧密码,新密码String password = request.getParameter("password");String password2 = request.getParameter("password2");//获取读者数据表中的密码String old_password = adminbean.getPassword();//对旧密码进行比较,如果相同就修改,不相同就直接退出if(old_password.equals(password)){admindao.updateUser(adminbean.getAid(), adminbean.getUsername(), password2, adminbean.getName(),adminbean.getEmail(), adminbean.getPhone(), adminbean.getLend_num(), adminbean.getMax_num());response.sendRedirect(url+".jsp");}else{out.write("<script type='text/javascript'>alert('password error');location.href='"+url+".jsp';  </script>");}} else {//修改个人资料//获取输入的信息String name = request.getParameter("name");String email = request.getParameter("email");String phone = request.getParameter("phone");//修改输入的信息到数据表中admindao.updateUser(adminbean.getAid(), adminbean.getUsername(), adminbean.getPassword(), name,email, phone, adminbean.getLend_num(), adminbean.getMax_num());response.sendRedirect(url+".jsp");}}}

四、源码

点击以下链接(内含数据库文件——books.sql):

链接:https://pan.baidu.com/s/1HN8CY281ctJWjSkynUgxag?pwd=5ugw 
提取码:5ugw 

五、备注 

该项目是基于一位GitHub上的大佬的项目模板写的,我在上课时按照老师的要求给原项目增加和优化了一些功能,最后变成了现在这个样子。由于当时在GitHub参考了很多的项目,导致我现在已经不记得那位大佬的用户名了,只能说是非常抱歉了。

如有侵权,请联系我删除。

六、祝福

路虽远行则可至,未来一定可期!祝您生活愉快、工作顺心、学业有成!

阅读本书更多章节>>>>

本文链接:https://www.kjpai.cn/gushi/2024-03-26/149004.html,文章来源:网络cs,作者:璐璐,版权归作者所有,如需转载请注明来源和作者,否则将追究法律责任!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。

文章评论