src/java/Controllers/CartController.java
/**
     * Handles the HTTP <code>POST</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 POST 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 POST 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 doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession(false);
        SearchDAO searchDAO = new SearchDAO();
        String roomId = request.getParameter("room_id");
        String checkInDate = request.getParameter("check_in");
        String checkOutDate = request.getParameter("check_out");
        String cardNumber = request.getParameter("card_number");
        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 || roomId == null || roomId.equals("") || diff <= 0 )
        {
            request.setAttribute("message_cart", "Please enter valid data!");
            RequestDispatcher rd = request.getRequestDispatcher("views/404.jsp");
            rd.forward(request, response);
            return;
        }
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        reservation.setCheckInDate(checkInDate);
        reservation.setCheckOutDate(checkOutDate);
        reservation.setRoomId(Integer.parseInt(roomId));
        reservation.setStatus("pending");
        reservation.setUserId(Integer.parseInt(session.getAttribute("user_id").toString()));
        reservation.setCreationDate(formatter.format(date));
        int flag = reservationDAO.save(reservation);
        if(flag != 0)
        {
            roomDAO.updateRowByColumn("is_available", "0", Integer.parseInt(roomId));
            EmailSender.send(session.getAttribute("email").toString(), "Thank you for booking", reservation.toString());
            request.setAttribute("done", "done");
            RequestDispatcher rd = request.getRequestDispatcher("views/confirmation.jsp");  
            rd.forward(request, response);
        }
    }
@ Override protected void doPost ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { HttpSession session = request . getSession ( false ) ; SearchDAO searchDAO = new SearchDAO ( ) ; String roomId = request . getParameter ( "room_id" ) ; String checkInDate = request . getParameter ( "check_in" ) ; String checkOutDate = request . getParameter ( "check_out" ) ; String cardNumber = request . getParameter ( "card_number" ) ; 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 || roomId == null || roomId . equals ( "" ) || diff <= 0 ) { request . setAttribute ( "message_cart" , "Please enter valid data!" ) ; RequestDispatcher rd = request . getRequestDispatcher ( "views/404.jsp" ) ; rd . forward ( request , response ) ; return ; } SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ; Date date = new Date ( System . currentTimeMillis ( ) ) ; reservation . setCheckInDate ( checkInDate ) ; reservation . setCheckOutDate ( checkOutDate ) ; reservation . setRoomId ( Integer . parseInt ( roomId ) ) ; reservation . setStatus ( "pending" ) ; reservation . setUserId ( Integer . parseInt ( session . getAttribute ( "user_id" ) . toString ( ) ) ) ; reservation . setCreationDate ( formatter . format ( date ) ) ; int flag = reservationDAO . save ( reservation ) ; if ( flag != 0 ) { roomDAO . updateRowByColumn ( "is_available" , "0" , Integer . parseInt ( roomId ) ) ; EmailSender . send ( session . getAttribute ( "email" ) . toString ( ) , "Thank you for booking" , reservation . toString ( ) ) ; request . setAttribute ( "done" , "done" ) ; RequestDispatcher rd = request . getRequestDispatcher ( "views/confirmation.jsp" ) ; rd . forward ( request , response ) ; } }
Handles the HTTP <code>POST</code> method.
Handles the HTTP <code > POST< / code > method .