基于javaweb的图书管理系统

基于javaweb的图书管理系统

码农世界 2024-06-06 前端 101 次浏览 0个评论

一、系统简介

本项目采用eclipse工具开发,jsp+servlet技术编写,样式采用了layui前端框架,数据库采用的是mysql,navicat开发工具。

系统一共分为2个角色分别是:管理员,学生

二、模块简介
管理员


1、登录

2、修改个人信息

3、图书类型管理

4、图书管理

5、图书借阅管理

6、借阅审批管理

7、图书借阅统计

8、学生管理

9、公告管理

学生

1、登录、注册

2、个人信息修改

3、图书借阅

4、借阅管理

5、借阅统计

6、查看公告

三、相关截图

项目结构、数据库结构

 

 登录注册页面

 

 图书类型管理

 图书管理

 学生管理

 审批管理

 

借阅管理

 公告管理

 管理员统计

 学生统计

 图书借阅

 借阅历史

 四、相关代码

登录代码

用户通过login.jsp页面填写指定的用户名和密码,点击登录按钮,执行servlet里面的方法,后台校验成功后,返回main.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>


	
		
		Login Page
		
		
		
登  录 图 书 管 理 系 统 ${message} 去注册
	private void login(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		removeAll(request,response);
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		String type = request.getParameter("type");
		if(type.equals("1")){
			Admin admin = new Admin();
			admin.setUserName(userName);
			admin.setPwd(password);
			Admin admin1 = ls.selectAdmin(admin);
			  try {
					 if (admin1 == null){
			        	  request.setAttribute("message", "管理员用户不存在或者密码错误");
						  request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
			         }else {
			        	  request.getSession().setAttribute("admin",admin1);
			        	  request.getSession().setAttribute("flag",1);
			              request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
			         }				
				 } catch (Exception e) {
				 	e.printStackTrace();
				 }
		 }else if(type.equals("2")){
			 Student student = new Student();
			 student.setStno(userName);
			 student.setPwd(password);
			 Student student1 = ls.selectStudent(student);
			  try {
					 if (student1 == null){
			        	  request.setAttribute("message", "学号不存在或者密码错误");
						  request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
			         }else {
			        	  request.getSession().setAttribute("student",student1);
			        	  request.getSession().setAttribute("flag",2);
			              request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
			         }				
				 } catch (Exception e) {
				 	e.printStackTrace();
				 }
		 }else{
			    request.setAttribute("message", "工作人员手机号不存在或者密码错误");
			    try {
				request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
				} catch (Exception e) {
					e.printStackTrace();
				} 
		 }
	}

注册代码

学生初始化注册自己的账号,填写form表单,提价后,后台进行插入的操作,注册成功后跳转登录页面

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>


	
		
		Login Page
		
		
		
注  册 图 书 管 理 系 统 ${message} 返回
	/**
	 * 新增学生信息
	 * @param request
	 * @param response
	 */
	private void addStudent(HttpServletRequest request,
			HttpServletResponse response) {
		String te = request.getParameter("te");
		String name = request.getParameter("name");
		String sex = request.getParameter("sex");
		String classes = request.getParameter("classes");
		String time = request.getParameter("time");
		String xy = request.getParameter("xy");
		String phone = request.getParameter("phone");
		String pwd = request.getParameter("pwd");
		String stno = request.getParameter("stno");
		Student stu = new Student();
		stu.setClasses(classes);
		stu.setName(name);
		stu.setPhone(phone);
		stu.setPwd(pwd);
		stu.setSex(sex);
		stu.setState("1");
		stu.setStno(stno);
		stu.setTime(time);
		stu.setXy(xy);
		Student student = ss.selectStudentByPhone(phone);
		Student student1 = ss.selectStudentByStuNo(stno);
		if(te == null || te.equals("")){
			if(student != null){
				request.setAttribute("message", "电话号码重复!");
				try {
					request.getRequestDispatcher("/WEB-INF/views/student/addStudent.jsp").forward(request,response);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else if(student1 != null){
				request.setAttribute("message", "学号重复!");
				try {
					request.getRequestDispatcher("/WEB-INF/views/student/addStudent.jsp").forward(request,response);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else{
				try {
					ss.saveStudent(stu);
		 			response.sendRedirect(request.getContextPath()+"/StudentServlet?action=studentList");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		}else{
			if(student != null){
				request.setAttribute("message", "电话号码重复!");
				try {
					request.getRequestDispatcher("/WEB-INF/views/register.jsp").forward(request,response);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else if(student1 != null){
				request.setAttribute("message", "学号重复!");
				try {
					request.getRequestDispatcher("/WEB-INF/views/register.jsp").forward(request,response);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else{
				try {
					ss.saveStudent(stu);
		 			response.sendRedirect(request.getContextPath()+"/LoginServlet?action=toLogin");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		}
		
	}

学生列表代码

后台分页查询所有学生的信息,返回到studentList.jsp中,进行遍历展示

	/**
	 * 分页查询学生
	 * @param request
	 * @param response
	 */
	private void studentList(HttpServletRequest request,
			HttpServletResponse response) {
		String p=request.getParameter("p");//接收页码
        int pageSize=4;//每页显示5条
        int pageNum=1; //默认第一页
        if(p!=null){
            pageNum= Integer.parseInt(p);
        }
        //调用分页查询
        List list=ss.getstudentListPage(pageNum,pageSize);
        //携带参数到页面
        int nums=ss.queryStudentCount(); //查询总数
        //计算总页数
        int totalPage=(nums%pageSize==0)? (nums/pageSize):(nums/pageSize+1);
        request.setAttribute("cp",pageNum); //当前页
        request.setAttribute("tp",totalPage); //总页数
		try {
         request.removeAttribute("msg");
         request.setAttribute("list" ,list);
           request.getRequestDispatcher("/WEB-INF/views/student/studentList.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


	
		
			学生列表
			
				
新增学生 <%-- --%>
<%-- --%>
姓名 性别 班级 入学时间 学院 手机号 密码 学号 操作
${u.name } ${u.sex } ${u.classes } ${u.time } ${u.xy } 不能 ${u.phone } ${u.pwd } ${u.stno } 修改 删除 <%-- 删除 --%>
首页 <%-- 判断是否有上一页--%> 上一页 <%-- 循环显示页码--%> <%-- 判断是否是当前页--%> ${e} ${e} <%-- 判断是否有下一页--%> 下一页 尾页 2 3 4

新增学生代码

点击新增按钮跳转addStudent.jsp页面,用户填写相关信息后提交代码到studentservlet里面,进行插入操作后返回页面,遍历展示信息

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


 
  
    
      
        
          新增学生
          
             
${message}
返回
/**
	 * 新增学生信息
	 * @param request
	 * @param response
	 */
	private void addStudent(HttpServletRequest request,
			HttpServletResponse response) {
		String te = request.getParameter("te");
		String name = request.getParameter("name");
		String sex = request.getParameter("sex");
		String classes = request.getParameter("classes");
		String time = request.getParameter("time");
		String xy = request.getParameter("xy");
		String phone = request.getParameter("phone");
		String pwd = request.getParameter("pwd");
		String stno = request.getParameter("stno");
		Student stu = new Student();
		stu.setClasses(classes);
		stu.setName(name);
		stu.setPhone(phone);
		stu.setPwd(pwd);
		stu.setSex(sex);
		stu.setState("1");
		stu.setStno(stno);
		stu.setTime(time);
		stu.setXy(xy);
		Student student = ss.selectStudentByPhone(phone);
		Student student1 = ss.selectStudentByStuNo(stno);
		if(te == null || te.equals("")){
			if(student != null){
				request.setAttribute("message", "电话号码重复!");
				try {
					request.getRequestDispatcher("/WEB-INF/views/student/addStudent.jsp").forward(request,response);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else if(student1 != null){
				request.setAttribute("message", "学号重复!");
				try {
					request.getRequestDispatcher("/WEB-INF/views/student/addStudent.jsp").forward(request,response);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else{
				try {
					ss.saveStudent(stu);
		 			response.sendRedirect(request.getContextPath()+"/StudentServlet?action=studentList");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		}else{
			if(student != null){
				request.setAttribute("message", "电话号码重复!");
				try {
					request.getRequestDispatcher("/WEB-INF/views/register.jsp").forward(request,response);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else if(student1 != null){
				request.setAttribute("message", "学号重复!");
				try {
					request.getRequestDispatcher("/WEB-INF/views/register.jsp").forward(request,response);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else{
				try {
					ss.saveStudent(stu);
		 			response.sendRedirect(request.getContextPath()+"/LoginServlet?action=toLogin");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		}
		
	}

修改学生代码

页面点击修改按钮,跳转到修改的页面,用户修改制定内容后提交代码,执行action里面的servlet路径,serlvet执行相关代码后,返回到前端展示数据!!!!!

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


  
    
      
        
          修改学生
          
             
${message}
返回 重置
	/**
	 * 修改学生信息
	 * @param request
	 * @param response
	 */
	private void updateStudent(HttpServletRequest request,
			HttpServletResponse response) {
		Object flag = request.getSession().getAttribute("flag");
		String sid = request.getParameter("sid");
		String name = request.getParameter("name");
		String sex = request.getParameter("sex");
		String classes = request.getParameter("classes");
		String time = request.getParameter("time");
		String xy = request.getParameter("xy");
		String phone = request.getParameter("phone");
		String pwd = request.getParameter("pwd");
		String stno = request.getParameter("stno");
		Student stu = new Student();
		stu.setClasses(classes);
		stu.setName(name);
		stu.setPhone(phone);
		stu.setPwd(pwd);
		stu.setSex(sex);
		stu.setStno(stno);
		stu.setTime(time);
		stu.setXy(xy);
		stu.setId(Integer.parseInt(sid));
		try {
			ss.updateStudent(stu);
			if(flag != null && flag.toString().equals("1")){
				response.sendRedirect(request.getContextPath()+"/StudentServlet?action=studentList");
			}else{
				response.sendRedirect(request.getContextPath()+"/StudentServlet?action=toUpdateStudent&id="+sid);
			}
 			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

其他模块代码都是类似的,此项目适合初学者学习借鉴,项目整体比较简单!!!!!!!

喜欢的朋友的点赞加关注,感兴趣的同学可以研究!!!!!

感谢  = v =

转载请注明来自码农世界,本文标题:《基于javaweb的图书管理系统》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,101人围观)参与讨论

还没有评论,来说两句吧...

Top