0

I created a jsp file in the WebContent folder, which has a form.

The action of the form is a Servlet, but when I click on the submit button, I get this message :

enter image description here

And this is my project structure :

enter image description here

How can I solve this problem ?

Edit 1:

this my jsp file :

<%@ include file="inc/header.jsp" %>
<h1>Créer un compte!</h1>

<form action="Registration" method="post">
    <fieldset>
        <legend>Informations personnels</legend>
        <label for="nom">Nom </label>
        <input type="text" name="nom">
        <label for="prenom">Prénom </label>
        <input type="text" name="prenom">
        <label for="email">E-Mail </label>
        <input type="text" name="email">
        <label for="sexe">Sexe </label>
        <div class="radio_check">
            <input type="radio" value="F" name="sexe"> Mâle
            <input type="radio" value="F" name="sexe"> Female
        </div>
        <label for="dateNaissance">Date de naissance : </label>
        <input type="datetime" name="dateNaissance">
    </fieldset>
    <fieldset>
        <legend>Infos de connexion</legend>
        <label for="pseudo">Pseudo </label>
        <input type="text" name="pseudo">
        <label for="mdp">Mot de passe </label>
        <input type="text" name="mdp">
        <label for="mdp2">Confirmation du mot de passe </label>
        <input type="text" name="mdp2">
        <div class="radio_check">
            <label for="abonner"><input type="checkbox" name="abonner">Abonnez-vous au blog</label>
        </div>
    </fieldset>
    <input type="submit" value="Créer un compte">
</form>

<%@ include file="inc/footer.jsp" %> 

And this is my Servlet :

package com.tp1.servlets;

    import java.io.IOException;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.tp1.beans.Compte;
    
    /**
     * Servlet implementation class Authentification
     */
    @WebServlet("/Authentification")
    public class Registration extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        public Registration() {
            super();
        }
    
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String nom              = request.getParameter("nom");
            String prenom           = request.getParameter("prenom");
            String email            = request.getParameter("email");
            String sexe             = request.getParameter("sexe");
            Date dateNaissance;
            try {
                dateNaissance = new SimpleDateFormat("dd-MM-yyyy").parse(request.getParameter("dateNaissance"));
            } catch (ParseException e) {
                dateNaissance = new Date();
            }
            String pseudo           = request.getParameter("pseudo");
            String mdp              = request.getParameter("mdp");
            Boolean abonner         = request.getParameter("abonner") == "on" ? true : false;
            
            Compte c = new Compte(nom, prenom, email, sexe, dateNaissance, pseudo, mdp, abonner);
            
            request.setAttribute("compte", c);
            
            this.getServletContext().getRequestDispatcher("signup_successful.jsp").forward(request, response);
        }
    
    }
Community
  • 1
  • 1
Renaud is Not Bill Gates
  • 1,684
  • 34
  • 105
  • 191
  • Please update your question and add some code, maybe the servlet and the JSP?! – Patrick Feb 09 '14 at 20:48
  • 1
    Change @WebServlet("/Authentication") to @WebServlet("/Registration") or call Authentication instead of Registration – Patrick Feb 09 '14 at 21:05

2 Answers2

1

The JSP keeps unchanged.

and here is the code of the servlet:

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;

@WebServlet("/Registration")
public class Registration extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 3480182983284787792L;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String nom              = request.getParameter("nom");
        String prenom           = request.getParameter("prenom");
        String email            = request.getParameter("email");
        String sexe             = request.getParameter("sexe");
        Date dateNaissance;
        try {
            dateNaissance = new SimpleDateFormat("dd-MM-yyyy").parse(request.getParameter("dateNaissance"));
        } catch (ParseException e) {
            dateNaissance = new Date();
        }
        String pseudo           = request.getParameter("pseudo");
        String mdp              = request.getParameter("mdp");
        Boolean abonner         = request.getParameter("abonner") == "on" ? true : false;

        Compte c = new Compte(nom, prenom, email, sexe, dateNaissance, pseudo, mdp, abonner);

        request.setAttribute("compte", c);

        ServletContext context = getServletContext();
        context.getRequestDispatcher("signup_successful.jsp").forward(request, response);
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        processRequest(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        processRequest(req, resp);
    }


}

I only added one method more, is called processRequest, sometimes you have the same ops in doGet and doPost for example and so you only need to change one part and it effects to the others also.

Hope this solves your prob. Patrick

Patrick
  • 4,532
  • 2
  • 26
  • 32
0

i think we can call doPost() method in doGet() too.

try this and tell us.

hope it'll help you.