/**
  * Permet de repondre a une requete web En affichant la liste des Spectacles et representations :
  * Utiliste JQuery javascript pour la mise en forme
  *
  * @param HttpServletRequest request requete
  * @param HttpServletResponse response reponse
  * @throw IOException, ServletException
  * @return void
  */
 public void doGet(HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
   // Get the session object
   HttpSession session = req.getSession(true);
   // Get the output stream
   ServletOutputStream out = res.getOutputStream();
   res.setContentType("text/html");
   out.println("<HEAD><TITLE>Reservation de tickets </TITLE></HEAD><BODY>");
   out.println("<h1> Reservations de tickets </h1>");
   out.println("<BODY bgproperties=\"fixed\" background=\"/images/rideau.JPG\">");
   out.println("<p align=\"Right\"><font face=\"Monotype Corsiva\"style=\"font-size: 16pt\">");
   try {
     // Open the file that is the first
     // command line parameter
     String relativeWebPath = "/WEB-INF/files/JAVASCRIPTPROG.txt";
     String absoluteDiskPath = this.getServletContext().getRealPath(relativeWebPath);
     File file = new File(absoluteDiskPath);
     FileInputStream fstream = new FileInputStream(file);
     // Get the object of DataInputStream
     DataInputStream in = new DataInputStream(fstream);
     BufferedReader br = new BufferedReader(new InputStreamReader(in));
     String strLine;
     // Read File Line By Line
     while ((strLine = br.readLine()) != null) {
       // Print the content on the console
       out.println(strLine);
     }
     // Close the input stream
     in.close();
   } catch (Exception e) { // Catch exception if any
     out.println("Error: " + e.getMessage());
   }
   if (session.isNew() || session.getAttribute("session.PanierListe") == null)
     out.println("<a href=\"admin/admin.html\">Caddie (vide)</a></font><br></p>");
   else if (session.getAttribute("session.PanierListe") != null)
     if (((PanierListe) session.getAttribute("session.PanierListe")).getSize() > 0)
       out.println(
           "<a href=\"admin/admin.html\">afficher caddie("
               + ((PanierListe) session.getAttribute("session.PanierListe")).Liste.size()
               + "Representations dans le panier)"
               + "</a></font><br></p>");
   try {
     Utilisateur user = Utilitaires.Identification(this);
     out.println(Utilitaires.AffichageAchat(user));
   } catch (Exception e) {
     out.println(e.getMessage());
   }
   out.println("</BODY>");
   out.close();
 }
Пример #2
0
 private String cryptPassword(String pass) {
   byte[] uniqueKey = pass.getBytes();
   byte[] hash = null;
   try {
     hash = MessageDigest.getInstance("MD5").digest(uniqueKey);
   } catch (Exception e) { // Il ne doit jamais avoir d'erreurs ici
     e.printStackTrace();
   }
   StringBuffer hashString = new StringBuffer();
   for (int i = 0; i < hash.length; ++i) {
     String hex = Integer.toHexString(hash[i]);
     if (hex.length() == 1) {
       hashString.append('0');
       hashString.append(hex.charAt(hex.length() - 1));
     } else {
       hashString.append(hex.substring(hex.length() - 2));
     }
   }
   return hashString.toString();
 }
Пример #3
0
  /**
   * Permet de repondre a une requete web affiche le contenu du panier ansi que les differentes
   * Places disponible pour la Representation passee via la methode POST HTML Creation du panier ,
   * des différent Item mis dedans et le rajoute dans les cookie Du client si necessaire.
   *
   * @param HttpServletRequest request requete
   * @param HttpServletResponse response réponse
   * @throw IOException, ServletException
   * @return void
   */
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    HttpSession session = req.getSession(true);

    ServletOutputStream out = res.getOutputStream();
    res.setContentType("text/html");

    try {
      out.println("<HEAD><TITLE>Panier</TITLE></HEAD><BODY>");
      out.println("<h1>Contenu du panier:</h1>");
      out.println("<BODY bgproperties=\"fixed\" background=\"/images/rideau.JPG\">");

      String nom = req.getParameter("nom");
      String num = req.getParameter("num");
      String date = req.getParameter("date");
      String place = req.getParameter("place");
      String rang = req.getParameter("rang");
      SimpleDateFormat s = new SimpleDateFormat("dd/MM/yyyy HH");
      // ajout d'une place au panier

      if (place != null && rang != null && num != null && date != null) {
        if (session.getAttribute("session.PanierListe") != null) {
          ((PanierListe) session.getAttribute("session.PanierListe"))
              .addPlace(num, date, place, rang);
          if ((String) session.getAttribute("session.log") != null) {
            // utilisateur loggé
            out.println("votre panier est enregistre");
            Utilisateur user = Utilitaires.Identification(this);
            out.println(
                Utilitaires.enregistrerPlacePanier(
                    user, (String) session.getAttribute("session.log"), num, date, place, rang));
          }
        }
      }
      if (nom != null && num != null && date != null) {
        if (session.getAttribute("session.PanierListe") != null) {
          if (!((PanierListe) session.getAttribute("session.PanierListe"))
              .In(new Integer(num), date))
            ((PanierListe) session.getAttribute("session.PanierListe"))
                .Liste.add(
                    new Item(
                        new Spectacle(nom, new Integer(num)),
                        new Representation(new Integer(num), s.parse(date))));
        } else {
          // creation d'un nouveau panier
          PanierListe p = new PanierListe();
          p.Liste.add(
              new Item(
                  new Spectacle(new String(nom), new Integer(num)),
                  new Representation(new Integer(num), s.parse(date))));
          session.setAttribute("session.PanierListe", p);
        }
      }
      // attention desormais le caddie est obligatoirement alloué
      if (session.getAttribute("session.PanierListe") != null && date != null && num != null) {
        out.println("contenu  actuel du caddie:<br>");
        out.println(((PanierListe) session.getAttribute("session.PanierListe")).toString());
        out.println(
            "<h1>Veuillez selectionner une place pour la representation numero: "
                + num
                + "a la date du : "
                + date
                + ":</h1><br>");
        // Affichage des places Dispo pour la representation:
        Utilisateur user = Utilitaires.Identification(this);
        out.println(Utilitaires.AffichagePlaceAchat(user, num, date));
        out.println("<form class=\"link\" action=Validate \"method=POST>\n");
        out.println("<button type=\"submit\">VALIDER LE PANIER</button>\n");
        out.println("</form>");
      } else out.println("Le caddie est vide<br>");

      out.println("<hr><p><font color=\"#FFFFFF\"><a href=\"/index.html\">Accueil</a></p>");
      out.close();

    } catch (Exception e) { // Catch exception if any
      out.println("Error: " + e.getMessage());
    }
  }