protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        BookService bookService = (BookService) getServletContext().getAttribute("bookService");//呼叫service
        
        int booksCount = bookService.getBooksCount();//取得book總數
        int size = (request.getParameter("size") != null) ? Integer.parseInt(request.getParameter("size")) : 10;//檢查目前page,size
        int page = (request.getParameter("page") != null) ? Integer.parseInt(request.getParameter("page")) : 1;//此變數名稱固定在getBooksPages()方法裡

        List<StringBuilder> pages = getBooksPages("ShowBookList.view", booksCount, size);//計算需要頁面且回傳超連結
        Set<Book> bookSet = bookService.getAllBook(Math.min(page, pages.size()), size);//根據page與size查找資料庫book,page不超過size

        request.setAttribute("page", page);//給頁面目前page
        request.setAttribute("size", size);//給頁面目前size
        request.setAttribute("booksPage", bookSet);//給搜尋結果
        request.setAttribute("pagesCount", pages);//給超連結
        request.getRequestDispatcher("BookList.jsp").forward(request, response);
//         BookService bookService=(BookService) getServletContext().getAttribute("bookService");
//       
//         
//
//        request.setAttribute("bookSet", bookService.getAllBook());//List給頁面
//        request.getRequestDispatcher("BookList.jsp").forward(request, response);
//         String Result = gson.toJson(bookList); 
//       String Result = gson.toJson(booksPrint);            

//		       try {  
//		    	  	   PrintWriter out = response.getWriter();  
//		    	  	   out.print(Result);
//		    	   	   out.close();  
//		    	   	  } catch (IOException e) {  
//		    	   		System.out.println(e);   
//		    	   	  }  



//        response.setContentType("text/html;charset=UTF-8");
//        PrintWriter out = response.getWriter();
//        try {
//            /* TODO output your page here. You may use following sample code. */
//            out.println("<!DOCTYPE html>");
//            out.println("<html>");
//            out.println("<head>");
//            out.println("<title>Servlet ShowBookList</title>");            
//            out.println("</head>");
//            out.println("<body>");
//            out.println("<h1>Servlet ShowBookList at " +bookSet+ "</h1>");
//            out.println("</body>");
//            out.println("</html>");
//        } finally {            
//            out.close();
//        }
       
        
    }