samedi 27 juin 2015

Tomcat server makes 3 requests to the servlet

Below is my doGet method

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    int page;
    try {
        page = Integer.parseInt(request.getParameter("page"));
    } catch (NumberFormatException e) {
        page = 1;
    }
    String sortBy = request.getParameter("sortBy");
    if (sortBy == null || sortBy.isEmpty())
        sortBy = this.getInitParameter("sortBy");

    String query = getQuery(sortBy);
    Object[] params = {
            (page - 1) * Constants.RESULTS_PER_PAGE,
            Constants.RESULTS_PER_PAGE
    };

    JDBCService service = new JDBCService(pool);
    service.setQuery(query);
    service.setParams(params);
    List<Book> books = service.getBookDetails();


    System.out.println("Hello");

    RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/index.jsp");
    dispatcher.forward(request, response);
}

When I start the server (Tomcat) the doGet method gets called 3 times. It prints 'Hello' 3 times.

This only happen when I first start the server.

Any idea why this happens?

Aucun commentaire:

Enregistrer un commentaire