×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Nhan Tran
Added: Aug 8, 2021 3:15 AM
Views: 3658
Tags: no tags
  1. private static final String HOME_PAGE = "HomePage.jsp";
  2.     private static final Integer RANGE = 10;
  3.     static Logger log = Logger.getLogger(SearchAccountServlet.class);
  4.  
  5.     /**
  6.      *
  7.      * @param request
  8.      * @param response
  9.      * @throws ServletException
  10.      * @throws IOException
  11.      */
  12.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  13.             throws ServletException, IOException {
  14.         response.setContentType("text/html;charset=UTF-8");
  15.         String url = HOME_PAGE;
  16.         String searchValue = request.getParameter("txtSearch");
  17.         String index = request.getParameter("txtIndex");
  18.         try {
  19.             request.setAttribute("s", searchValue);
  20.             if (index == null) {
  21.                 index = "0";
  22.             }
  23.             if (searchValue == null) {
  24.                 searchValue = "";
  25.             }
  26.             AccountDAO dao = new AccountDAO();
  27.             List<Account> searchList = dao.getSearchingAccount(Integer.parseInt(index), RANGE, searchValue);
  28.             request.setAttribute("searchList", searchList);
  29.             int searchCount = dao.count(RANGE, searchValue);
  30.             request.setAttribute("searchCount", searchCount);
  31.         } catch (NumberFormatException | SQLException | NamingException ex) {
  32.             log.warn(ex.getClass().getSimpleName() + "SearchAccountServlet" + "_Exception :  " + ex.getMessage());
  33.         } finally {
  34.             request.getRequestDispatcher(url).forward(request, response);
  35.         }
  36.     }