commit 577d05689abb2153a37d9396c3fea3691a4adfce Author: sio Date: Thu Oct 3 11:52:44 2024 +0200 persitance des données (1) diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..90f3582 --- /dev/null +++ b/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project Test2JakartaV7-2. + + + diff --git a/nbproject/ant-deploy.xml b/nbproject/ant-deploy.xml new file mode 100644 index 0000000..785fa0b --- /dev/null +++ b/nbproject/ant-deploy.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..84d69dc --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1436 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..e128caa --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=ff2a0cb9 +build.xml.script.CRC32=dffdee25 +build.xml.stylesheet.CRC32=1707db4f@1.98.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=ff2a0cb9 +nbproject/build-impl.xml.script.CRC32=f38222bd +nbproject/build-impl.xml.stylesheet.CRC32=334708a0@1.98.0.1 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..1d275df --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,90 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +# Files to be excluded from distribution war +dist.archive.excludes= +dist.dir=dist +dist.ear.war=${dist.dir}/${war.ear.name} +dist.javadoc.dir=${dist.dir}/javadoc +dist.war=${dist.dir}/${war.name} +endorsed.classpath= +excludes= +file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar=../../../../Users/sio/Downloads/jakarta.servlet.jsp.jstl-2.0.0.jar +file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar=../../../../Users/sio/Downloads/jakarta.servlet.jsp.jstl-api-2.0.0.jar +file.reference.mysql-connector-java-8.0.23.jar=C:\\Users\\sio\\Downloads\\mysql-connector-java-8.0.23.jar +file.reference.mysql-connector-java-8.0.23.jar-1=C:\\Program Files\\Apache Software Foundation\\Tomcat 10.1\\drivers\\mysql-connector-java-8.0.23.jar +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=10-web +j2ee.platform.classpath=${j2ee.server.home}/bin/tomcat-juli.jar:${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-ssi.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.27.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jakartaee-migration-1.0.8-shaded.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jaspic-api.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/mysql-connector-java-8.0.23.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote-ffm.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-cs.jar:${j2ee.server.home}/lib/tomcat-i18n-de.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-i18n-ko.jar:${j2ee.server.home}/lib/tomcat-i18n-pt-BR.jar:${j2ee.server.home}/lib/tomcat-i18n-ru.jar:${j2ee.server.home}/lib/tomcat-i18n-zh-CN.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar:${j2ee.server.home}/lib/websocket-client-api.jar +j2ee.server.type=Tomcat +jar.compress=false +javac.classpath=\ + ${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar}:\ + ${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar}:\ + ${file.reference.mysql-connector-java-8.0.23.jar}:\ + ${file.reference.mysql-connector-java-8.0.23.jar-1} +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=21 +javac.target=21 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=Test2JakartaV7-2.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..c2c6caa --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,35 @@ + + + org.netbeans.modules.web.project + + + Test2JakartaV7-2 + 1.6.5 + + + ${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 + + + ${file.reference.mysql-connector-java-8.0.23.jar} + WEB-INF/lib + + + ${file.reference.mysql-connector-java-8.0.23.jar-1} + WEB-INF/lib + + + + + + + + + + + + diff --git a/src/conf/MANIFEST.MF b/src/conf/MANIFEST.MF new file mode 100644 index 0000000..59499bc --- /dev/null +++ b/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/src/java/bdd/ClientMySQL.java b/src/java/bdd/ClientMySQL.java new file mode 100644 index 0000000..7082dcb --- /dev/null +++ b/src/java/bdd/ClientMySQL.java @@ -0,0 +1,56 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package bdd; + +import java.sql.Statement; +import javabeans.Client; +import java.util.ArrayList; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +/** + * + * @author sio + */ +public class ClientMySQL { + private final Connection theConnection = Connexion.getConnect("10.121.38.165", "bdclient", "adminBDClient", "mdpBDClient"); + + public void create(Client leClient){ + + } + + public Client read(int num){ + return null; + } + + public void update(int num){ + + } + + public void delete(int num){ + + } + + public ArrayList readAll(){ + ArrayList lesClients = new ArrayList<>(); + try{ + Statement stmt = theConnection.createStatement(); + ResultSet resultQ = null; + resultQ = stmt.executeQuery("SELECT * FROM client"); + while(resultQ.next()){ + String resultat = resultQ.getString("nom") + " " + resultQ.getString("prénom"); + lesClients.add(resultat); + } + resultQ.close(); + stmt.close(); + }catch (SQLException ex){ + System.out.println("SQLException : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return lesClients; + } +} diff --git a/src/java/bdd/Connexion.java b/src/java/bdd/Connexion.java new file mode 100644 index 0000000..4beee1c --- /dev/null +++ b/src/java/bdd/Connexion.java @@ -0,0 +1,61 @@ +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/gestionClient/AccueilServlet.java b/src/java/gestionClient/AccueilServlet.java new file mode 100644 index 0000000..e095e91 --- /dev/null +++ b/src/java/gestionClient/AccueilServlet.java @@ -0,0 +1,86 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template + */ +package gestionClient; + +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 famille Thevenot + */ +public class AccueilServlet 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 AccueilServlet"); + out.println(""); + out.println(""); + out.println("

Servlet AccueilServlet 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/accueilVue.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/gestionClient/AuthentifServlet.java b/src/java/gestionClient/AuthentifServlet.java new file mode 100644 index 0000000..e8512ca --- /dev/null +++ b/src/java/gestionClient/AuthentifServlet.java @@ -0,0 +1,95 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template + */ +package gestionClient; + +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; +import testForms.AuthentifForm; + +/** + * + * @author famille Thevenot + */ +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); + } + + /** + * 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); + //Création de l'objet leControl de type AuthentifForm + AuthentifForm leControle = new AuthentifForm(); + //Appel de la méthode controlerAdmin + Boolean isAdmin=leControle.controlerAdmin(request); + //création de 2 attributs de requête (isAdmin et leControle) + request.setAttribute("controlForm", leControle); + request.setAttribute("isAdmin", isAdmin); + //Affichage JSP + getServletContext().getRequestDispatcher("/WEB-INF/accueilVue.jsp").forward(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/gestionClient/ListeServlet2.java b/src/java/gestionClient/ListeServlet2.java new file mode 100644 index 0000000..2bdd931 --- /dev/null +++ b/src/java/gestionClient/ListeServlet2.java @@ -0,0 +1,93 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template + */ +package gestionClient; + +import bdd.ClientMySQL; +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * + * @author famille Thevenot + */ +@WebServlet(name = "ListeServlet2", urlPatterns = {"/ListeClients"}) +public class ListeServlet2 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 ListeServlet2"); + out.println(""); + out.println(""); + out.println("

Servlet ListeServlet2 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 { + System.out.println("ListeServlet2"); + ClientMySQL cli = new ClientMySQL(); + // parcourir la arraylist + //System.out.println(cli.readAll()); + request.setAttribute("laListe", cli.readAll()); + getServletContext().getRequestDispatcher("/WEB-INF/listeClientsVue.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/gestionClient/NouveauServlet.java b/src/java/gestionClient/NouveauServlet.java new file mode 100644 index 0000000..dccea91 --- /dev/null +++ b/src/java/gestionClient/NouveauServlet.java @@ -0,0 +1,85 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template + */ +package gestionClient; + +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 famille Thevenot + */ +public class NouveauServlet 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 NouveauServlet"); + out.println(""); + out.println(""); + out.println("

Servlet NouveauServlet 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 { + getServletContext().getRequestDispatcher("/WEB-INF/nouveauClientVue.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/javabeans/Client.java b/src/java/javabeans/Client.java new file mode 100644 index 0000000..08badea --- /dev/null +++ b/src/java/javabeans/Client.java @@ -0,0 +1,42 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package javabeans; + +/** + * + * @author sio + */ +public class Client { + //variables membres + private int id; + private String nom; + private String mail; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } + + +} diff --git a/src/java/javabeans/User.java b/src/java/javabeans/User.java new file mode 100644 index 0000000..9bf6d95 --- /dev/null +++ b/src/java/javabeans/User.java @@ -0,0 +1,66 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package javabeans; + +import java.util.Objects; + +/** + * + * @author famille Thevenot + */ +public class User { + private String pseudo; + private String motDePasse; + + public User(String pseudo, String motDePasse) { + this.pseudo = pseudo; + this.motDePasse = motDePasse; + } + + public User(String header) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + public String getPseudo() { + return pseudo; + } + + public void setPseudo(String pseudo) { + this.pseudo = pseudo; + } + + public String getMotDePasse() { + return motDePasse; + } + + public void setMotDePasse(String motDePasse) { + this.motDePasse = motDePasse; + } + + @Override + public int hashCode() { + int hash = 5; + 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; + } + return Objects.equals(this.motDePasse, other.motDePasse); + } + +} diff --git a/src/java/testForms/AuthentifForm.java b/src/java/testForms/AuthentifForm.java new file mode 100644 index 0000000..c5f6366 --- /dev/null +++ b/src/java/testForms/AuthentifForm.java @@ -0,0 +1,38 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package testForms; + +import jakarta.servlet.http.HttpServletRequest; +import javabeans.User; + +/** + * + * @author famille Thevenot + */ +public class AuthentifForm { + private String resultat; + + public String getResultat() { + return resultat; + } + + public void setResultat(String resultat) { + this.resultat = resultat; + } + + public boolean controlerAdmin(HttpServletRequest request) + { + User admin = new User("admin", "minda"); + User userSaisi = new User(request.getParameter("ztPseudo"),request.getParameter("ztMDP")); + //test du compte admin + boolean isAdmin = userSaisi.equals(admin); + + //mise à jour de l'attribut resultat + setResultat(isAdmin?"Vous êtes administrateur":"Vous n'êtes pas administrateur"); + return isAdmin; + } + + +} diff --git a/web/META-INF/context.xml b/web/META-INF/context.xml new file mode 100644 index 0000000..6b8baeb --- /dev/null +++ b/web/META-INF/context.xml @@ -0,0 +1,2 @@ + + diff --git a/web/WEB-INF/accueilVue.jsp b/web/WEB-INF/accueilVue.jsp new file mode 100644 index 0000000..abcaf6c --- /dev/null +++ b/web/WEB-INF/accueilVue.jsp @@ -0,0 +1,43 @@ +<%-- + Document : accueilJSPV6 + Created on : 9 sept. 2024, 12:32:01 + Author : famille Thevenot +--%> + +<%@page import="testForms.AuthentifForm"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + + Accueil des clients + + + <%@include file="jspf/enteteClient.jspf" %> + <%@include file="jspf/menuClient.jspf" %> + +

Bienvenue sur la nouvelle application de gestion des clients écrite avec JakartaEE

+ + + + +

Bonjour ${param.ztPseudo }

+
+ + + +
+ +

+ +

+ +
+
+
+ + + + diff --git a/web/WEB-INF/jspf/enteteClient.jspf b/web/WEB-INF/jspf/enteteClient.jspf new file mode 100644 index 0000000..8d9d23f --- /dev/null +++ b/web/WEB-INF/jspf/enteteClient.jspf @@ -0,0 +1,3 @@ +<%-- any content can be specified here e.g.: --%> +<%@ page pageEncoding="UTF-8" %> +

Gestion des clients

diff --git a/web/WEB-INF/jspf/menuClient.jspf b/web/WEB-INF/jspf/menuClient.jspf new file mode 100644 index 0000000..135a9d6 --- /dev/null +++ b/web/WEB-INF/jspf/menuClient.jspf @@ -0,0 +1,10 @@ +<%-- any content can be specified here e.g.: --%> +<%@ page pageEncoding="UTF-8" %> + + diff --git a/web/WEB-INF/listeClientsVue.jsp b/web/WEB-INF/listeClientsVue.jsp new file mode 100644 index 0000000..2de9863 --- /dev/null +++ b/web/WEB-INF/listeClientsVue.jsp @@ -0,0 +1,23 @@ +<%-- + Document : listeClientsVue + Created on : 15 sept. 2024, 18:51:03 + Author : famille Thevenot +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + Liste des clients + + + <%@include file="jspf/enteteClient.jspf" %> + <%@include file="jspf/menuClient.jspf" %> +

Liste des clients

+

Page en construction2

+ + + + diff --git a/web/WEB-INF/nouveauClientVue.jsp b/web/WEB-INF/nouveauClientVue.jsp new file mode 100644 index 0000000..9554275 --- /dev/null +++ b/web/WEB-INF/nouveauClientVue.jsp @@ -0,0 +1,20 @@ +<%-- + Document : nouveauClientVue + Created on : 15 sept. 2024, 18:49:28 + Author : famille Thevenot +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Nouveau client + + + <%@include file="jspf/enteteClient.jspf" %> + <%@include file="jspf/menuClient.jspf" %> +

Nouveau client

+

Page en construction

+ + diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml new file mode 100644 index 0000000..1c86eed --- /dev/null +++ b/web/WEB-INF/web.xml @@ -0,0 +1,35 @@ + + + + ListeServlet + ListeServlet2 + + + AccueilServlet + gestionClient.AccueilServlet + + + NouveauServlet + gestionClient.NouveauServlet + + + AuthentifServlet + gestionClient.AuthentifServlet + + + ListeServlet2 + /listeClients + + + AccueilServlet + / + + + NouveauServlet + /nouveauClient + + + AuthentifServlet + /authentification + + diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..4cea0a0 --- /dev/null +++ b/web/index.html @@ -0,0 +1,15 @@ + + + + + TODO supply a title + + + + +
TODO write content
+ +