protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { BookDao dao = new BookDao(); if (request.getParameter("type") == null || request.getParameter("type").equals("全部类型")) { request.getSession().setAttribute("queryBooks", dao.queryBook(null, BookDao.QUERY_BY_TYPE)); } else { LinkedList<Book> list = dao.queryBook(request.getParameter("type"), BookDao.QUERY_BY_TYPE); request.getSession().setAttribute("queryBooks", list); } request.getSession().setAttribute("who", "book"); request.getRequestDispatcher("/back_stage.jsp").forward(request, response); dao.giveBack(); }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String bookname = request.getParameter("bookname"); byte[] bytes = bookname.getBytes("ISO-8859-1"); bookname = new String(bytes, "UTF-8"); HttpSession session = request.getSession(); BookDao dao = new BookDao(); LinkedList<Book> list = new LinkedList<>(); LinkedList<Book> sessionkList = (LinkedList<Book>) session.getAttribute("queryBooks"); if (sessionkList != null) { for (Book book : sessionkList) { if (book.getName().contains(bookname)) { list.add(book); break; } } } session.setAttribute("queryBooks", list); session.setAttribute("who", "book"); // 显示书 request.getRequestDispatcher("/back_stage.jsp").forward(request, response); dao.giveBack(); }