Java项目:图书管理系统(java+swing+Gui+Mysql)

Posted pastclouds

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java项目:图书管理系统(java+swing+Gui+Mysql)相关的知识,希望对你有一定的参考价值。

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

功能介绍:借阅列表、图书类别管理、图书馆里、用户管理、借阅管理、关于我们

  

 

登录服务类:

@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");
		
	


添加用户服务类:

@WebServlet("/AddUserServlet")
public class AddUserServlet extends HttpServlet 
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddUserServlet() 
        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"));
	
		AdminDao userdao = new AdminDao();
		//调用函数添加读者信息
		userdao.Register(username,password,name,email,phone,lend_num,max_num);
        response.sendRedirect("/books/admin_user.jsp");
	


添加图书服务类:

@WebServlet("/AddBookServlet")
public class AddBookServlet extends HttpServlet 
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddBookServlet() 
        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"));
		BookDao bookdao = new BookDao();
		//调用函数,存入图书
		bookdao.addBook(card,name,type,autho,press,num);
		response.sendRedirect("/books/admin_book.jsp");
	


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

以上是关于Java项目:图书管理系统(java+swing+Gui+Mysql)的主要内容,如果未能解决你的问题,请参考以下文章

Java项目:图书管理系统(java+swing+Gui+Mysql)

Java swing项目-图书管理系统(swing+mysql+jdbc) 总结

Java Swing 期末大作业-----图书借阅管理系统

基于Java swing+mysql+eclipse的图书管理系统

基于Java swing+mysql+eclipse的图书管理系统

Mysql学习基于Swing+jdbc+mysql的Java图书管理系统保姆级教程