Ejemplo n.º 1
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // recupération de la personne en base
    Integer profileId = Integer.valueOf(request.getParameter("profileId"));
    // recherche de la personne à modifier
    Personne updatedPerson = new Personne();
    updatedPerson.setId(profileId);
    updatedPerson = gestionEcoleService.rechercherPersonne(updatedPerson).get(0);
    // affectation des nouvelles valeurs
    String inputNom = request.getParameter("inputNom");
    updatedPerson.setNom(inputNom);
    String inputPrenom = request.getParameter("inputPrenom");
    updatedPerson.setPrenom(inputPrenom);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
    String inputDateNaissString = request.getParameter("inputDateNaiss");
    try {
      Date inputDateNaiss = simpleDateFormat.parse(inputDateNaissString);
      updatedPerson.setDateNaiss(inputDateNaiss);
    } catch (ParseException e) {
      throw new RuntimeException(e);
    }

    String inputPassword = request.getParameter("inputPassword");
    if (inputPassword != null && !inputPassword.isEmpty()) {
      updatedPerson.setPassw(inputPassword);
    }

    String inputPromotionString = request.getParameter("inputPromotion");
    if (!inputPromotionString.isEmpty()) {
      Integer inputPromotion = Integer.valueOf(inputPromotionString);
      Promotion searchPromotion = new Promotion();
      searchPromotion.setId(inputPromotion);
      searchPromotion = gestionEcoleService.rechercherPromotion(searchPromotion).get(0);
      updatedPerson.setPromotion(searchPromotion);
    } else {
      updatedPerson.setPromotion(null);
    }

    // mise à jour
    updatedPerson = gestionEcoleService.updatePersonne(updatedPerson);

    request.setAttribute("personneSelected", updatedPerson);
    RequestDispatcher dispatcher = request.getRequestDispatcher("/TP5_Controller");
    dispatcher.forward(request, response);
  }
Ejemplo n.º 2
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    List<Personne> personList = new ArrayList<Personne>();

    personList.clear();
    for (Integer i = 0; i < 10; i++) {
      Personne personne = new Personne();
      personne.setId(i);
      personne.setNom(i.toString());
      personne.setPrenom(i.toString());
      personne.setDateNaiss(new Date());
      personList.add(personne);
    }

    response.setCharacterEncoding("UTF8");
    PrintWriter printWriter = response.getWriter();
    printWriter.println("<!DOCTYPE html>");
    printWriter.println("<html>");
    printWriter.println("<head>");
    printWriter.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>");
    String design = getServletConfig().getInitParameter("design");
    if (design != null) {
      printWriter.println(
          "<link rel=\"stylesheet\" media=\"screen\" type=\"text/css\" title=\"style\" href=\""
              .concat(getServletConfig().getInitParameter("design"))
              .concat(".css\"/>"));
    } else {
      printWriter.println(
          "<link rel=\"stylesheet\" media=\"screen\" type=\"text/css\" title=\"style\" href=\""
              .concat("rouge")
              .concat(".css\"/>"));
    }
    printWriter.println("</head>");
    printWriter.println("<body>");
    String paramName = request.getParameter("name");
    if (paramName != null) {
      printWriter.println(
          "<p class=\"designColor\">Hello World! "
              .concat(request.getParameter("name"))
              .concat("</p>"));
    } else {
      printWriter.println("<p class=\"designColor\">Hello World!</p>");
    }
    printWriter.println("<br/>");
    printWriter.println("<br/>");
    // Presentation du tableau
    printWriter.println("<table>");
    printWriter.println("<thead><tr>");
    printWriter.println("<th>id</th><th>Nom</th><th>Prenom</th><th>Date de naissance</th>");
    printWriter.println("</tr></thead>");
    // Remplissage du tableau-----------------------------
    printWriter.println("<tbody>");
    for (Personne personne : personList) {
      printWriter.println("<tr>");
      printWriter.println("<td>".concat(personne.getId().toString()).concat("</td>"));
      printWriter.println("<td>".concat(personne.getNom()).concat("</td>"));
      printWriter.println("<td>".concat(personne.getPrenom()).concat("</td>"));
      printWriter.println("<td>".concat(personne.getDateNaiss().toString()).concat("</td>"));
      printWriter.println("</tr>");
    }
    printWriter.println("</tbody>");
    printWriter.println("</table>");
    // ----------------------------------------
    printWriter.println("</body>");
    printWriter.println("</html>");
  }
Ejemplo n.º 3
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    PrintWriter printWriter = response.getWriter();

    Integer ligne = null;
    String ligneParam = request.getParameter("ligne");
    if (ligneParam != null) {
      ligne = Integer.valueOf(ligneParam);
    }

    if (ligne != null) {
      System.out.println("numero de ligne cliquée : ".concat(String.valueOf(ligne)));
    }

    List<Personne> personnes = new ArrayList<Personne>();

    Promotion promotion = new Promotion();
    promotion.setLibelle("CDI09");

    Personne personne1 = new Personne();
    personne1.setNom("toto");
    personne1.setPrenom("toto");
    personne1.setDateNaiss(new Date());
    personne1.setPromotion(promotion);
    personnes.add(personne1);

    Personne personne2 = new Personne();
    personne2.setNom("tata");
    personne2.setPrenom("tata");
    personne2.setDateNaiss(new Date());
    personne2.setPromotion(promotion);
    personnes.add(personne2);

    printWriter.println("<!DOCTYPE html>");
    printWriter.println("<html>");
    printWriter.println("<head>");
    printWriter.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
    printWriter.println("</head>");
    printWriter.println("<body>");
    printWriter.println(
        "<table><thead><tr><th>nom</th><th>prenom</th><th>date naissance</th><th>promotion</th></tr></thead><tbody>");
    Integer cpt = 1;
    for (Personne personne : personnes) {
      printWriter.println(
          "<tr><td>"
              .concat(personne.getNom())
              .concat("</td><td>")
              .concat(personne.getPrenom())
              .concat("</td><td>")
              .concat(personne.getDateNaiss().toString())
              .concat("</td><td>")
              .concat(personne.getPromotion() != null ? personne.getPromotion().getLibelle() : "")
              .concat("</td><td>")
              .concat(
                  "<a href=\"./TP7?ligne="
                      .concat(String.valueOf(cpt++))
                      .concat("\">afficher ligne dans console</a>"))
              .concat("</td></tr>"));
    }
    printWriter.println("</tbody></table>");

    printWriter.println("</body>");
    printWriter.println("</html>");
  }