Java毕业设计项目实战篇|Java项目:网上图书馆管理系统(java+jsp+servlert+mysql+ajax)

源码获取:博客首页 "资源" 里下载!
一、项目简述
功能: 区分为管理员用户和普通用户,普通用户:用户登录,个 人信息修改,图书查询,用户借阅,用户归还,管理员用 户:图书馆里,归还管理,借阅信息查询,图书维护,分 类管理,读者管理等等功能。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP + Servlert + html+ css + JavaScript + JQuery + Ajax等等。
Java毕业设计项目实战篇|Java项目:网上图书馆管理系统(java+jsp+servlert+mysql+ajax)
文章图片


Java毕业设计项目实战篇|Java项目:网上图书馆管理系统(java+jsp+servlert+mysql+ajax)
文章图片

【Java毕业设计项目实战篇|Java项目:网上图书馆管理系统(java+jsp+servlert+mysql+ajax)】Java毕业设计项目实战篇|Java项目:网上图书馆管理系统(java+jsp+servlert+mysql+ajax)
文章图片

Java毕业设计项目实战篇|Java项目:网上图书馆管理系统(java+jsp+servlert+mysql+ajax)
文章图片


读者信息控制层:
/** * Servlet implementation class updateUserServlet */ @WebServlet("/updateUserServlet") public class updateUserServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public updateUserServlet() { 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"); 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"); int lend_num = Integer.parseInt(request.getParameter("lend_num")); int max_num = Integer.parseInt(request.getParameter("max_num")); int aid = Integer.parseInt(request.getParameter("aid")); AdminDao userdao = new AdminDao(); userdao.updateUser(aid,username,password,name,email,phone,lend_num,max_num); response.sendRedirect("/books/admin_user.jsp"); }}

图书信息控制层:
/** * Servlet implementation class updateBookServlet */ @WebServlet("/updateBookServlet") public class updateBookServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public updateBookServlet() { 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"); 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"); }}


登录信息控制层:
/** * 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 { // TODO Auto-generated method stub //doGet(request, response); //登录的判断 PrintWriter out = response.getWriter(); request.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); //获取账号和密码 String username = request.getParameter("username"); String password = request.getParameter("password"); AdminDao userdao = new AdminDao(); //对账号和密码进行判断 boolean result = userdao.Login_verify(username, password); HttpSession session = request.getSession(); //判断输入正确 if(result){ AdminBean adminbean = new AdminBean(); AdminDao admindao = new AdminDao(); //更加账号和密码查找出读者的信息 adminbean = admindao.getAdminInfo(username,password); //将aid存入session中 session.setAttribute("aid", ""+adminbean.getAid()); //设置session的失效时间 session.setMaxInactiveInterval(6000); //根据status的值来判断是管理员,还是读者,status=1为读者 if(adminbean.getStatus()==1){ response.sendRedirect("/books/index2.jsp"); }else{ response.sendRedirect("/books/admin.jsp"); } }else{ //没有找到对应的账号和密码,返回重新登录 session.setAttribute("state", "密码错误"); response.sendRedirect("/books/login.jsp"); } }}


管理员信息控制层:
/** * Servlet implementation class AdminServlet */ @WebServlet("/AdminServlet") public class AdminServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @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 //doGet(request, response); 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"); 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"); 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("/books/"+url+".jsp"); }else{ out.write(""); } }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("/books/"+url+".jsp"); } }}

源码获取:博客首页 "资源" 里下载!

    推荐阅读