-1

the user have to type the link /creationClient to see the creation form put the informations and with my servlet i take those informations check them and forward the user to another page to show the informations he's putted. the problem is with my doGet method. here is the code.

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            //processRequest(request, response);
            this.getServletContext().getRequestDispatcher("/CreerClient.jsp").forward(request, response);

            String nom= request.getParameter("nomClient");
            String prenom = request.getParameter("prenomClient");
            String adresse = request.getParameter("adresseClient");
            String telephone= request.getParameter("telephoneClient");
            String email=  request.getParameter("emailClient");
            String message;
            if(nom.trim().isEmpty() || telephone.trim().isEmpty() || adresse.trim().isEmpty()){
                message= "Erreur, Remplissez tous les champs obligatoires.</br> <a href=\"CreerClient.jsp\" Retour au formulaire de creation d'un Client";
            }else
            {
                message="Creation résussie!";
            }
            Client client = new Client();
            client.setNom(nom);
            client.setPrenom(prenom);
            client.setAdresse(adresse);
            client.setTelephone(telephone);
            client.setEmail(email);
            request.setAttribute("client", client);
            request.setAttribute("message", message);
            this.getServletContext().getRequestDispatcher("AfficherClient.jsp").forward(request, response);
        }
RockAndRoll
  • 2,247
  • 2
  • 16
  • 35

3 Answers3

0

If you are already saving the data to a database you can retrieve the data again from the second page.

Since your code does not show any database activity at the moment I'd say your best option is to store the data in the session. See for example How do you store Java objects in HttpSession?

Community
  • 1
  • 1
Simon Groenewolt
  • 10,607
  • 1
  • 36
  • 64
  • A database isn't the answer to this question. Have to fix this problem before adding more complexity. – Don Branson Oct 12 '15 at 11:57
  • @DonBranson I meant if the data was going into a database anyway and didn't mean to imply actually starting to use a database just for this. I'll edit my answer. – Simon Groenewolt Oct 12 '15 at 13:34
0

Here's your problem, the first line of your doGet method:

this.getServletContext().getRequestDispatcher("/CreerClient.jsp").forward(request, response);

And in the last line of your method, you have another forward:

this.getServletContext().getRequestDispatcher("AfficherClient.jsp").forward(request, response);

Not sure why you have 2 invocations of forward(). Try removing the first line of code.

Ish
  • 3,992
  • 1
  • 17
  • 23
-1

I saw my mistake. First i had to remove the line 4 forwarding. Then I had to invoke the filling form page by it's name (CreerClient.jsp) me i was calling it directly wis the pattern of the servlet(/creationClient) reason why i putted the first forwading to make it show up. Now if i call it from it's name name and submit the form i have the right results. Thanks you all for your help. Just one last question, if i got you, i shouldn't use two forwadings in a same doGet method?