From f008779cbeed322aabac9262d2b8c6e0710381c2 Mon Sep 17 00:00:00 2001 From: "thomas.millot" Date: Mon, 18 Oct 2021 14:32:43 +0200 Subject: [PATCH] --- nbproject/build-impl.xml | 4 + nbproject/genfiles.properties | 6 +- nbproject/project.properties | 6 +- nbproject/project.xml | 8 ++ src/java/bdd/ClientMysql.java | 22 +++++ src/java/bdd/Connexion.java | 62 +++++++++++++ src/java/com/test/beans/User.java | 62 +++++++++++++ .../com/test/servlets/AuthentifServlet.java | 87 +++++++++++++++++++ src/java/com/test/servlets/ModifServlet.java | 87 +++++++++++++++++++ src/java/com/test/servlets/ProfilServlet.java | 87 +++++++++++++++++++ ...icationJSP.jsp => AuthentificationJSP.jsp} | 0 web/WEB-INF/web.xml | 28 ++++++ 12 files changed, 455 insertions(+), 4 deletions(-) create mode 100644 src/java/bdd/ClientMysql.java create mode 100644 src/java/bdd/Connexion.java create mode 100644 src/java/com/test/beans/User.java create mode 100644 src/java/com/test/servlets/AuthentifServlet.java create mode 100644 src/java/com/test/servlets/ModifServlet.java create mode 100644 src/java/com/test/servlets/ProfilServlet.java rename web/WEB-INF/{authentificationJSP.jsp => AuthentificationJSP.jsp} (100%) create mode 100644 web/WEB-INF/web.xml diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 2a72a7a..8102b7a 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -983,11 +983,15 @@ exists or setup the property manually. For example like this: + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 53f22be..795fef0 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=742a8c7e +build.xml.data.CRC32=573ee386 build.xml.script.CRC32=9c118765 build.xml.stylesheet.CRC32=1707db4f@1.86.0.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=742a8c7e -nbproject/build-impl.xml.script.CRC32=d51427e0 +nbproject/build-impl.xml.data.CRC32=573ee386 +nbproject/build-impl.xml.script.CRC32=7458d665 nbproject/build-impl.xml.stylesheet.CRC32=334708a0@1.86.0.1 diff --git a/nbproject/project.properties b/nbproject/project.properties index 4b54e1e..93b0dd7 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -28,6 +28,8 @@ dist.war=${dist.dir}/${war.name} endorsed.classpath=\ ${libs.javaee-endorsed-api-7.0.classpath} excludes= +file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar=/home/thomas.millot/T\u00e9l\u00e9chargements/jakarta.servlet.jsp.jstl-2.0.0.jar +file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar=/home/thomas.millot/T\u00e9l\u00e9chargements/jakarta.servlet.jsp.jstl-api-2.0.0.jar file.reference.mysql-connector-java-8.0.26.jar=/usr/share/java/mysql-connector-java-8.0.26.jar includes=** j2ee.compile.on.save=true @@ -38,7 +40,9 @@ j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.serve j2ee.server.type=Tomcat jar.compress=false javac.classpath=\ - ${file.reference.mysql-connector-java-8.0.26.jar} + ${file.reference.mysql-connector-java-8.0.26.jar}:\ + ${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar}:\ + ${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar} # Space-separated list of extra javac options javac.compilerargs= javac.debug=true diff --git a/nbproject/project.xml b/nbproject/project.xml index 0f2ea31..ccc65a8 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -10,6 +10,14 @@ ${file.reference.mysql-connector-java-8.0.26.jar} WEB-INF/lib + + ${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar} + WEB-INF/lib + + + ${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar} + WEB-INF/lib + diff --git a/src/java/bdd/ClientMysql.java b/src/java/bdd/ClientMysql.java new file mode 100644 index 0000000..e5a5cfb --- /dev/null +++ b/src/java/bdd/ClientMysql.java @@ -0,0 +1,22 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package bdd; + +import java.sql.Connection; + +/** + * + * @author thomas.millot + */ +public class ClientMysql { + + private Connection theConnection; + + public ClientMysql() + { + theConnection = Connexion.getConnect("localhost", "sdis29", "admin", "minda"); + } +} diff --git a/src/java/bdd/Connexion.java b/src/java/bdd/Connexion.java new file mode 100644 index 0000000..feb365f --- /dev/null +++ b/src/java/bdd/Connexion.java @@ -0,0 +1,62 @@ +package bdd; +/* +Connexion.java +Classe permettant d'établir une connexion avec une base de données mySQL +*/ +import java.sql.Connection; +import java.sql.DriverManager; + +public class Connexion { + private static Connection connect; // Variable de connexion + + /** + * Constructeur + * @param serveur nom du serveur, localhost si local + * @param bdd nom de la base de données + * @param nomUtil nom utilisateur + * @param mdp mot de passe lié à l'utilisateur + */ + private Connexion(String serveur, String bdd, String nomUtil, String mdp) { + try { + // 1. Chargement du driver + //Class.forName("com.mysql.jdbc.Driver"); + Class.forName("com.mysql.cj.jdbc.Driver"); + System.out.println("Driver accessible"); + + // 2. Initialisation des paramètres de connexion + String host = serveur; // Serveur de bd + String dbname = bdd; // Nom bd + String url = "jdbc:mysql://" + host + "/" + dbname; // url de connexion + //url += "?autoReconnect=true"; // Ajout 26/09/2021 + System.out.println("url : "+url); + String user = nomUtil; // nom du user + System.out.println("nomUtil : "+nomUtil); + String passwd = mdp; // mot de passe + System.out.println("mdp : "+mdp); + + // 3. Connexion + connect = (Connection) DriverManager.getConnection(url, user, passwd); + System.out.println("Connexion réussie !"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Retourne la connection établie (Création d'une connection si elle n'existe pas) + * @param serveur nom du serveur, localhost si local + * @param bdd nom de la base de données + * @param nomUtil nom utilisateur + * @param mdp mot de passe lié à l'utilisateur + * @return connection établie + */ + public static Connection getConnect(String serveur, String bdd, String nomUtil, String mdp) { + System.out.println("getConnect"); + if (connect == null) { + new Connexion(serveur, bdd, nomUtil, mdp); + } + return connect; + } + +} diff --git a/src/java/com/test/beans/User.java b/src/java/com/test/beans/User.java new file mode 100644 index 0000000..ee2e6c6 --- /dev/null +++ b/src/java/com/test/beans/User.java @@ -0,0 +1,62 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.test.beans; + +import java.util.Objects; +/** + * + * @author thomas.millot + */ +public class User { + private String pseudo; + private String mdp; + + public User(String pseudo, String mdp){ + this.pseudo = pseudo; + this.mdp = mdp; + } + + public String getPseudo(){ + return pseudo; + } + + public String getMdp(){ + return mdp; + } + + public void setMdp(){ + this.mdp = mdp; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + Objects.hashCode(this.pseudo); + hash = 31 * hash + Objects.hashCode(this.mdp); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final User other = (User) obj; + if (!Objects.equals(this.pseudo, other.pseudo)) { + return false; + } + if (!Objects.equals(this.mdp, other.mdp)) { + return false; + } + return true; + } +} diff --git a/src/java/com/test/servlets/AuthentifServlet.java b/src/java/com/test/servlets/AuthentifServlet.java new file mode 100644 index 0000000..ac6403c --- /dev/null +++ b/src/java/com/test/servlets/AuthentifServlet.java @@ -0,0 +1,87 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.test.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * + * @author Dominique_2 + */ +public class AuthentifServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * 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 { + response.setContentType("text/html;charset=UTF-8"); + try ( PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet AuthentifServlet"); + out.println(""); + out.println(""); + out.println("

Servlet AuthentifServlet at " + request.getContextPath() + "

"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + //processRequest(request, response); + getServletContext().getRequestDispatcher("/WEB-INF/AuthentificationJSP.jsp").forward(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/src/java/com/test/servlets/ModifServlet.java b/src/java/com/test/servlets/ModifServlet.java new file mode 100644 index 0000000..ae8838c --- /dev/null +++ b/src/java/com/test/servlets/ModifServlet.java @@ -0,0 +1,87 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.test.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * + * @author Dominique_2 + */ +public class ModifServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * 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 { + response.setContentType("text/html;charset=UTF-8"); + try ( PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet ModifServlet"); + out.println(""); + out.println(""); + out.println("

Servlet ModifServlet at " + request.getContextPath() + "

"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + //processRequest(request, response); + getServletContext().getRequestDispatcher("/WEB-INF/ModifProfilJSP.jsp").forward(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} \ No newline at end of file diff --git a/src/java/com/test/servlets/ProfilServlet.java b/src/java/com/test/servlets/ProfilServlet.java new file mode 100644 index 0000000..a2214bb --- /dev/null +++ b/src/java/com/test/servlets/ProfilServlet.java @@ -0,0 +1,87 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.test.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * + * @author Dominique_2 + */ +public class ProfilServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * 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 { + response.setContentType("text/html;charset=UTF-8"); + try ( PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet ProfilServlet"); + out.println(""); + out.println(""); + out.println("

Servlet ProfilServlet at " + request.getContextPath() + "

"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + //processRequest(request, response); + getServletContext().getRequestDispatcher("/WEB-INF/ProfilJSP.jsp").forward(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} \ No newline at end of file diff --git a/web/WEB-INF/authentificationJSP.jsp b/web/WEB-INF/AuthentificationJSP.jsp similarity index 100% rename from web/WEB-INF/authentificationJSP.jsp rename to web/WEB-INF/AuthentificationJSP.jsp diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml new file mode 100644 index 0000000..cd4db47 --- /dev/null +++ b/web/WEB-INF/web.xml @@ -0,0 +1,28 @@ + + + + + AuthentifServlet + com.test.servlets.AuthentifServlet + + + ModifServlet + com.test.servlets.ModifServlet + + + ProfilServlet + com.test.servlets.ProfilServlet + + + AuthentifServlet + /authentif + + + ModifServlet + /Modif + + + ProfilServlet + /Profil + +