/** * 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 { User utilisateur = new User( request.getParameter("nom"), request.getParameter("prenom"), request.getParameter("mdp")); String cheminComplet = this.getServletContext().getRealPath("/WEB-INF/users.properties"); if (utilisateur.comparaison(cheminComplet) == true) { request.setAttribute("utilisateur", utilisateur); RequestDispatcher disp = getServletContext().getRequestDispatcher("/bonjour.jsp"); disp.forward(request, response); } else { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet controlleur</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1> NON </h1>"); out.println("<h1>Servlet controlleur at " + request.getContextPath() + "</h1>"); out.println("<h1>nom html " + request.getParameter("nom") + "</h1>"); out.println("<h1>prenom html" + request.getParameter("prenom") + "</h1>"); out.println("<h1>mdp html " + request.getParameter("mdp") + "</h1>"); out.println("<h1>nom " + utilisateur.getNom() + "</h1>"); out.println("<h1>prenom " + utilisateur.getPrenom() + "</h1>"); out.println("<h1>mdp " + utilisateur.getMdp() + "</h1>"); out.println("</body>"); out.println("</html>"); } } }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub HttpSession session = request.getSession(); int idUser; ArrayList<User> liste = (ArrayList<User>) session.getAttribute("listes"); idUser = liste.get(0).getId_Utilisateur(); EditUserModel eu = new EditUserModel(); String spseudo = request.getParameter("pseudo"); String semail = request.getParameter("email"); String sprenom = request.getParameter("prenom"); String snom = request.getParameter("nom"); int slangue = 2; if (request.getParameter("langue").equals("English")) { slangue = 2; } else { slangue = 1; } User u = new User(); u.setId_Utilisateur(idUser); u.setPseudo(spseudo); u.setEmail(semail); u.setPrenom(sprenom); u.setNom(snom); u.setId_langue(slangue); try { eu.ModifUser(u, idUser); liste.clear(); liste.add(u); session.setAttribute("listes", liste); request.setAttribute("user", u); request.getRequestDispatcher("Account.jsp").forward(request, response); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }