Web应用程序的预订表格

时间:2018-07-12 13:45:27

标签: java mysql database jsp

我正在创建一个简单的Web应用程序,已经创建了预订房间的可能性,但是我需要对日期进行控制。我需要检查是否有人在某个日期预订房间,而其他人无法在同一数据中预订房间。因此,如果您在2018年12月7日预订,没有人可以在2018年12月7日预订相同类型的房间。 我该如何实施? 感谢您的关注。

这是我的

  

Hotelbooking.java

package hotel;


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 *
 * @author OOPs
 */
public class Hotelbooking extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String s1 = request.getParameter("id");
        String s2 = request.getParameter("name");
           String s3 = request.getParameter("email");
           String s4 = request.getParameter("arrivaldate");
           String s5 = request.getParameter("departuredate");
           String s6 = request.getParameter("person");
           String s7 = request.getParameter("rooms");
           String s8 = request.getParameter("type_room");
           String s9 = request.getParameter("comment");
           String s10 = request.getParameter("status");

           // sesson..........
           HttpSession session=request.getSession(true);
          String s11 = (String)session.getAttribute("sessname");

       out.println(s11);




       try {


            Class.forName("com.mysql.jdbc.Driver");
      //  out.println("driver loaded");
     Connection  con = DriverManager.getConnection("jdbc:mysql://localhost:3306/HotelReservation","root" ,"123456789");
      //  out.println("Connect");
      Statement  st =  con.createStatement();
        //  out.println("conncetion successfull");


       int rs =  st.executeUpdate("insert into hotel_booking (cname,email,arrival_date,departure_date,person,room,type_room,comment,status,uid)values ('"+s2+"','"+s3+"','"+s4+"','"+s5+"','"+s6+"','"+s7+"','"+s8+"','"+s9+"','"+s10+"','"+s11+"')");
         // out.println(s1);
         // out.println(s2);
          out.println("<h1> Register sucsefulltttt </h1>");

          /* if(rs == 1)
           {
           out.println("<script type=\"text/javascript\">");
       out.println("alert('send successfully');");
       out.println("</script>");
       //response.sendRedirect("home.jsp");
           }else{


       }*/

          response.sendRedirect("thankyou.jsp"); 



        }catch(Exception e){
        out.println("nahiiiiiiiiiiiii" +e);
        }
        finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * 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
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * 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
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

0 个答案:

没有答案