基于javaweb的图书管理系统

一、系统简介

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

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

二、模块简介
管理员

1、登录

2、修改个人信息

3、图书类型管理

4、图书管理

5、图书借阅管理

6、借阅审批管理

7、图书借阅统计

8、学生管理

9、公告管理

学生
1、登录、注册

2、个人信息修改

3、图书借阅

4、借阅管理

5、借阅统计

6、查看公告

三、相关截图

项目结构、数据库结构

图片[1] - 基于javaweb的图书管理系统 - MaxSSL

图片[2] - 基于javaweb的图书管理系统 - MaxSSL

登录注册页面

图片[3] - 基于javaweb的图书管理系统 - MaxSSL

图片[4] - 基于javaweb的图书管理系统 - MaxSSL

图书类型管理

图片[5] - 基于javaweb的图书管理系统 - MaxSSL

图书管理

图片[6] - 基于javaweb的图书管理系统 - MaxSSL

学生管理

图片[7] - 基于javaweb的图书管理系统 - MaxSSL

审批管理

图片[8] - 基于javaweb的图书管理系统 - MaxSSL

借阅管理

图片[9] - 基于javaweb的图书管理系统 - MaxSSL

公告管理

图片[10] - 基于javaweb的图书管理系统 - MaxSSL

管理员统计

图片[11] - 基于javaweb的图书管理系统 - MaxSSL

学生统计

图片[12] - 基于javaweb的图书管理系统 - MaxSSL

图书借阅

图片[13] - 基于javaweb的图书管理系统 - MaxSSL

借阅历史

图片[14] - 基于javaweb的图书管理系统 - MaxSSL

四、相关代码

登录代码

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

Login Page图片[15] - 基于javaweb的图书管理系统 - MaxSSL登  录 图书管理系统${message}  去注册 layui.use(['layer', 'form','jquery'], function(){var form = layui.form, layer = layui.layer, $= layui.jquery; form.render();//这句一定要加,占坑 $("#login").on("click", function() {var userName = $("#userName").val().trim(); // trim()去除空格var password = $("#password").val().trim();var type = $("#type").val();if(userName == ""){layer.msg('用户名或者手机号不能为空!');return false;}if(password == ""){layer.msg('密码不能为空!');return false;}if(type == ""){layer.msg('请选择角色!');return false;}});setTimeout(function(){ $("#msg").html("")},3000);setTimeout(function(){ $("#msg2").html("")},3000);setTimeout(function(){ $("#msg3").html("")},3000);});
private void login(HttpServletRequest request, HttpServletResponse response) {// TODO Auto-generated method stubremoveAll(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表单,提价后,后台进行插入的操作,注册成功后跳转登录页面

Login Page 图片[15] - 基于javaweb的图书管理系统 - MaxSSL注  册 图书管理系统${message}请选择性别男女      返回 layui.use(['layer', 'form','jquery','laydate'], function(){var form = layui.form, layer = layui.layer, laydate=layui.laydate, $= layui.jquery; form.render();//这句一定要加,占坑laydate.render({elem: '#time'});$("#login").on("click", function() {var name = $("#name").val();var sex = $("#sex").val();var classes = $("#classes").val();var time = $("#time").val();var xy = $("#xy").val();var phone = $("#phone").val();var pwd = $("#pwd").val();var stno = $("#stno").val();if(sex == null || sex== ""){layer.msg('性别不能为空!');return false;}if(name == null || name== ""){layer.msg('姓名不能为空!');return false;}if(classes == null || classes== ""){layer.msg('班级不能为空!');return false;}if(time == null || time== ""){layer.msg('入学时间不能为空!');return false;}if(xy == null || xy== ""){layer.msg('学院不能为空!');return false;}if(phone == null || phone== ""){layer.msg('手机号不能为空!');return false;}if(pwd == null || pwd== ""){layer.msg('密码不能为空!');return false;}if(stno == null || stno== ""){layer.msg('学号不能为空!');return false;}});setTimeout(function(){ $("#msg").html("")},3000);setTimeout(function(){ $("#msg2").html("")},3000);setTimeout(function(){ $("#msg3").html("")},3000);});
/** * 新增学生信息 * @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();}}
学生列表  新增学生<%--  --%>  <!--  --><%--  --%>
姓名性别班级入学时间学院能否借阅书籍手机号密码学号操作
${u.name }${u.sex }${u.classes }${u.time }${u.xy }不能 ${u.phone }${u.pwd }${u.stno }修改 删除<%-- 删除 --%>
首页1}">上一页1 ? (cp-2) :1}"end="${cp+2>tp?tp:(cp+2)}" var="e">${e}${e}<c:if test="${cp下一页尾页 234layui.use([ 'form','jquery','layer','laydate' ], function() {var form = layui.form, layer = layui.layer, laydate=layui.laydate, $= layui.jquery; form.render();//这句一定要加,占坑 $('a.layui-btn-danger').click(function(e){var id = $(e.currentTarget).parent().find('.weui-input').attr('id'); if(confirm("确定要删除吗?")){ $.post("StudentServlet?action=deleteStudent&id="+id, function(data) {layer.msg('删除成功!',{icon:6,offset:"auto",time:2000},function(){document.location.reload();//当前页面});});} })laydate.render({elem: '#time',type: 'year'});});

新增学生代码

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

  新增学生  ${message}请选择性别男女 
返回layui.use([ 'form','jquery','layer','laydate' ], function() {var form = layui.form, layer = layui.layer, laydate=layui.laydate, $= layui.jquery; form.render();//这句一定要加,占坑laydate.render({elem: '#time'});$(function () {// 给注册绑定单击事件i$("#sub_btn").click(function () {var name = $("#name").val();var sex = $("#sex").val();var classes = $("#classes").val();var time = $("#time").val();var xy = $("#xy").val();var phone = $("#phone").val();var pwd = $("#pwd").val();var stno = $("#stno").val();if(sex == null || sex== ""){layer.msg('性别不能为空!');return false;}if(name == null || name== ""){layer.msg('姓名不能为空!');return false;}if(classes == null || classes== ""){layer.msg('班级不能为空!');return false;}if(time == null || time== ""){layer.msg('入学时间不能为空!');return false;}if(xy == null || xy== ""){layer.msg('学院不能为空!');return false;}if(phone == null || phone== ""){layer.msg('手机号不能为空!');return false;}if(pwd == null || pwd== ""){layer.msg('密码不能为空!');return false;}if(stno == null || stno== ""){layer.msg('学号不能为空!');return false;}});setTimeout(function(){ $("#errorMsg").html("")},3000);}); setTimeout(function(){ $("#msg3").html("")},3000);});
/** * 新增学生信息 * @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执行相关代码后,返回到前端展示数据!!!!!

 修改学生   ${message}请选择性别 男女  男女 
返回 重置 layui.use([ 'form','jquery','layer','laydate' ], function() {var form = layui.form, layer = layui.layer, laydate=layui.laydate, $= layui.jquery; form.render();//这句一定要加,占坑laydate.render({elem: '#time'});$(function () {// 给注册绑定单击事件$("#sub_btn").click(function () {var name = $("#name").val();var sex = $("#sex").val();var classes = $("#classes").val();var time = $("#time").val();var xy = $("#xy").val();var phone = $("#phone").val();var pwd = $("#pwd").val();var stno = $("#stno").val();if(sex == null || sex== ""){layer.msg('性别不能为空!');return false;}if(name == null || name== ""){layer.msg('姓名不能为空!');return false;}if(classes == null || classes== ""){layer.msg('班级不能为空!');return false;}if(time == null || time== ""){layer.msg('入学时间不能为空!');return false;}if(xy == null || xy== ""){layer.msg('学院不能为空!');return false;}if(phone == null || phone== ""){layer.msg('手机号不能为空!');return false;}if(pwd == null || pwd== ""){layer.msg('密码不能为空!');return false;}if(stno == null || stno== ""){layer.msg('学号不能为空!');return false;}});setTimeout(function(){ $("#errorMsg").html("")},3000);}); setTimeout(function(){ $("#msg3").html("")},3000);});
/** * 修改学生信息 * @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 =

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享