96 CHAPTER 2: Building Web Applications Using Servlets and JSP
Listing 2-34 shows the helper method findAllBooks(request, response) in the BookController.
Listing 2-34. findAllBooks( ) in BookController
1.private void findAllBooks(HttpServletRequest request,
2.HttpServletResponse response) throws ServletException, IOException {
3.try {
4.BookDAO bookDao = new BookDAOImpl();
5.List
6.request.setAttribute("bookList", bookList);
7.
8.} catch (Exception e) {
9.System.out.println(e);
10.}
11.}
Lines 5 to 6: This list of all books is obtained from the database using the
findAllBooks() method on the DAO and is set as an attribute in the request.
Searching the Books by Category
When the user clicks a specific category on the menu, the list of books in that category is displayed,
as illustrated in Figure 2-38.
Figure 2-38. Searching the book by category