src/java/Controllers/CartController.java
/**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
Handles the HTTP GET method.

@param request servlet request
@param response servlet response
@throws ServletException if a servlet-specific error occurs
@throws IOException if an I/O error occurs
Handles the HTTP GET method . @param request servlet request @param response servlet response @throws ServletException if a servlet - specific error occurs @throws IOException if an I / O error occurs
@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession(false);
        SearchDAO searchDAO = new SearchDAO();
        if (session == null || session.getAttribute("user_id") == null) 
        {
            RequestDispatcher rd = request.getRequestDispatcher("views/404.jsp");
            rd.forward(request, response);
        }
        String hotelId = request.getParameter("id");
        String checkInDate = request.getParameter("check_in");
        String checkOutDate = request.getParameter("check_out");
        String adults = request.getParameter("adults");
        String children = request.getParameter("children");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        long diff = 1;
        try {
            Date dateStart = simpleDateFormat.parse(checkInDate);
            Date dateEnd = simpleDateFormat.parse(checkOutDate);
            diff = Math.round((dateEnd.getTime() - dateStart.getTime()) / (double) 86400000);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        if(session.getAttribute("user_id") == null || hotelId == null || hotelId.equals("") || diff <= 0 )
        {
            request.setAttribute("message_cart", "Please enter valid data!");
            RequestDispatcher rd = request.getRequestDispatcher("hotel?id=" + hotelId);
            rd.forward(request, response);
            return;
        }
        this.rooms = searchDAO.getRoomsBy(checkInDate, checkOutDate, adults, children, Integer.parseInt(hotelId));
        if(this.rooms.size() <= 0)
        {
            request.setAttribute("message_cart", "NO Rooms available!");
            RequestDispatcher rd = request.getRequestDispatcher("hotel?id=" + hotelId);
            rd.forward(request, response);
            return;
        }
        request.setAttribute("nights", diff);
        request.setAttribute("total_cost", this.rooms.get(0).getPricePerDay() * diff);
        request.setAttribute("room", this.rooms.get(0));
        System.out.println(this.rooms.get(0));
        RequestDispatcher rd = request.getRequestDispatcher("views/cart_hotel.jsp");  
        rd.forward(request, response);
    }
@ Override protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { HttpSession session = request . getSession ( false ) ; SearchDAO searchDAO = new SearchDAO ( ) ; if ( session == null || session . getAttribute ( "user_id" ) == null ) { RequestDispatcher rd = request . getRequestDispatcher ( "views/404.jsp" ) ; rd . forward ( request , response ) ; } String hotelId = request . getParameter ( "id" ) ; String checkInDate = request . getParameter ( "check_in" ) ; String checkOutDate = request . getParameter ( "check_out" ) ; String adults = request . getParameter ( "adults" ) ; String children = request . getParameter ( "children" ) ; SimpleDateFormat simpleDateFormat = new SimpleDateFormat ( "yyyy-MM-dd" ) ; long diff = 1 ; try { Date dateStart = simpleDateFormat . parse ( checkInDate ) ; Date dateEnd = simpleDateFormat . parse ( checkOutDate ) ; diff = Math . round ( ( dateEnd . getTime ( ) - dateStart . getTime ( ) ) / ( double ) 86400000 ) ; } catch ( ParseException ex ) { ex . printStackTrace ( ) ; } if ( session . getAttribute ( "user_id" ) == null || hotelId == null || hotelId . equals ( "" ) || diff <= 0 ) { request . setAttribute ( "message_cart" , "Please enter valid data!" ) ; RequestDispatcher rd = request . getRequestDispatcher ( "hotel?id=" + hotelId ) ; rd . forward ( request , response ) ; return ; } this . rooms = searchDAO . getRoomsBy ( checkInDate , checkOutDate , adults , children , Integer . parseInt ( hotelId ) ) ; if ( this . rooms . size ( ) <= 0 ) { request . setAttribute ( "message_cart" , "NO Rooms available!" ) ; RequestDispatcher rd = request . getRequestDispatcher ( "hotel?id=" + hotelId ) ; rd . forward ( request , response ) ; return ; } request . setAttribute ( "nights" , diff ) ; request . setAttribute ( "total_cost" , this . rooms . get ( 0 ) . getPricePerDay ( ) * diff ) ; request . setAttribute ( "room" , this . rooms . get ( 0 ) ) ; System . out . println ( this . rooms . get ( 0 ) ) ; RequestDispatcher rd = request . getRequestDispatcher ( "views/cart_hotel.jsp" ) ; rd . forward ( request , response ) ; }
Handles the HTTP <code>GET</code> method.
Handles the HTTP <code > GET< / code > method .