From d7334787cdc140ccd1a3fcfd2cd3e07ce2e5e2a5 Mon Sep 17 00:00:00 2001 From: sio Date: Mon, 14 Oct 2024 16:52:42 +0200 Subject: [PATCH] fin chap9 --- nbproject/project.properties | 180 ++++++++--------- src/java/bdd/ClientMySQL.java | 170 ++++++++-------- src/java/bdd/SalarieMySQL.java | 166 +++++++-------- src/java/gestionClient/ListeServlet2.java | 185 +++++++++-------- src/java/gestionClient/NouveauServlet.java | 224 ++++++++++----------- web/WEB-INF/listeClientsVue.jsp | 6 +- 6 files changed, 465 insertions(+), 466 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index e3e444f..c8451f8 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,90 +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=../../../../Users/sio/Downloads/mysql-connector-java-8.0.23.jar -file.reference.mysql-connector-java-8.0.23.jar-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/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=Test2JakartaV9.war -web.docbase.dir=web -webinf.dir=web/WEB-INF +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=../../../../Users/sio/Downloads/mysql-connector-java-8.0.23.jar +file.reference.mysql-connector-java-8.0.23.jar-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=Test2JakartaV9.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/src/java/bdd/ClientMySQL.java b/src/java/bdd/ClientMySQL.java index 1ee0497..2b3daa4 100644 --- a/src/java/bdd/ClientMySQL.java +++ b/src/java/bdd/ClientMySQL.java @@ -1,85 +1,85 @@ -/* - * 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 { - /*Connexion MV serveurBD lycée - private final Connection laConnection = Connexion.getConnect("10.121.38.165", "bdclient", "adminBDClient", "mdpBDClient");*/ - - /*Connexion wampserver - private final Connection laConnection = Connexion.getConnect("localhost", "bdclient", "adminBDClient", "mdpBDClient");*/ - - //connexion MV serveurBD maison - private final Connection laConnection = Connexion.getConnect("192.168.1.21", "bdclient", "adminBDClient", "mdpBDClient"); - - public int create(Client c){ - int id=-1; - try{ - Statement stmt = laConnection.createStatement(); - int status= stmt.executeUpdate( - " INSERT INTO client (nom, prenom, mail) VALUES ('" - +c.getNom() +"','" - +c.getPrenom() +"','" - +c.getMail() +"');", - Statement.RETURN_GENERATED_KEYS); - if (status>0) - { - ResultSet result=stmt.getGeneratedKeys(); - if (result.first()){ - id = result.getInt(1); - } - } - 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 id; - } - - 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 = laConnection.createStatement(); - ResultSet resultQ = null; - resultQ = stmt.executeQuery("SELECT * FROM client"); - while(resultQ.next()){ - String resultat = resultQ.getString("nom") + " " + resultQ.getString("prenom"); - 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; - } -} +/* + * 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 { + //Connexion MV serveurBD lycée + private final Connection laConnection = Connexion.getConnect("10.121.38.106", "bdclient", "adminBDClient", "mdpBDClient"); + + /*Connexion wampserver + private final Connection laConnection = Connexion.getConnect("localhost", "bdclient", "adminBDClient", "mdpBDClient");*/ + + //connexion MV serveurBD maison + //private final Connection laConnection = Connexion.getConnect("192.168.1.21", "bdclient", "adminBDClient", "mdpBDClient"); + + public int create(Client c){ + int id=-1; + try{ + Statement stmt = laConnection.createStatement(); + int status= stmt.executeUpdate( + " INSERT INTO client (nom, prenom, mail) VALUES ('" + +c.getNom() +"','" + +c.getPrenom() +"','" + +c.getMail() +"');", + Statement.RETURN_GENERATED_KEYS); + if (status>0) + { + ResultSet result=stmt.getGeneratedKeys(); + if (result.first()){ + id = result.getInt(1); + } + } + 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 id; + } + + 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 = laConnection.createStatement(); + ResultSet resultQ = null; + resultQ = stmt.executeQuery("SELECT * FROM client"); + while(resultQ.next()){ + String resultat = resultQ.getString("nom") + " " + resultQ.getString("prenom"); + 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/SalarieMySQL.java b/src/java/bdd/SalarieMySQL.java index d31ee17..7a176b4 100644 --- a/src/java/bdd/SalarieMySQL.java +++ b/src/java/bdd/SalarieMySQL.java @@ -1,83 +1,83 @@ -/* - * 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 java.util.ArrayList; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import javabeans.User; -/** - * - * @author sio - */ -public class SalarieMySQL { - /*Connexion MV serveurBD lycée - private final Connection laConnection = Connexion.getConnect("10.121.38.165", "bdclient", "adminBDClient", "mdpBDClient");*/ - - /*Connexion wampserver - private final Connection laConnection = Connexion.getConnect("localhost", "bdclient", "adminBDClient", "mdpBDClient");*/ - - //connexion MV serveurBD maison - private final Connection laConnection = Connexion.getConnect("192.168.1.21", "bdclient", "adminBDClient", "mdpBDClient"); - - - - public ArrayList readAll(){ - User leSalarie=new User("lo","log"); - ArrayList lesSalaries = new ArrayList<>(); - try{ - Statement stmt = laConnection.createStatement(); - ResultSet resultQ = null; - resultQ = stmt.executeQuery("SELECT * FROM salarie"); - while(resultQ.next()){ - leSalarie.setLogin(resultQ.getString("login")); - leSalarie.setId(resultQ.getInt("idSal")); - leSalarie.setMdp(resultQ.getString("mdp")); - leSalarie.setRole(resultQ.getBoolean("role")); - lesSalaries.add(leSalarie); - } - 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 lesSalaries; - } - - public User lireSalarie(String log, String m){ - User leSalarie=new User(); - ResultSet resultQ = null; - try{ - - PreparedStatement prepStmt = null; - - String sql = "SELECT * FROM Salarie WHERE login = ? AND mdp=?"; - prepStmt = laConnection.prepareStatement(sql); // pré-compilation - - prepStmt.setString(1, log); //le param. 1 est remplacé par "Toto" - prepStmt.setString(2,m); - resultQ = prepStmt.executeQuery(); - if (resultQ.first()){ - leSalarie.setLogin(resultQ.getString("login")); - leSalarie.setId(resultQ.getInt("idSal")); - leSalarie.setMdp(resultQ.getString("mdp")); - leSalarie.setRole(resultQ.getBoolean("role")); - } - resultQ.close(); - prepStmt.close(); - }catch (SQLException ex){ - System.out.println("SQLException : " + ex.getMessage()); - System.out.println("SQLState : " + ex.getSQLState()); - System.out.println("Code erreur : " + ex.getErrorCode()); - } - return leSalarie; - } -} +/* + * 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 java.util.ArrayList; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import javabeans.User; +/** + * + * @author sio + */ +public class SalarieMySQL { + //Connexion MV serveurBD lycée + private final Connection laConnection = Connexion.getConnect("10.121.38.106", "bdclient", "adminBDClient", "mdpBDClient"); + + /*Connexion wampserver + private final Connection laConnection = Connexion.getConnect("localhost", "bdclient", "adminBDClient", "mdpBDClient");*/ + + //connexion MV serveurBD maison + // private final Connection laConnection = Connexion.getConnect("192.168.1.21", "bdclient", "adminBDClient", "mdpBDClient"); + + + + public ArrayList readAll(){ + User leSalarie=new User("lo","log"); + ArrayList lesSalaries = new ArrayList<>(); + try{ + Statement stmt = laConnection.createStatement(); + ResultSet resultQ = null; + resultQ = stmt.executeQuery("SELECT * FROM salarie"); + while(resultQ.next()){ + leSalarie.setLogin(resultQ.getString("login")); + leSalarie.setId(resultQ.getInt("idSal")); + leSalarie.setMdp(resultQ.getString("mdp")); + leSalarie.setRole(resultQ.getBoolean("role")); + lesSalaries.add(leSalarie); + } + 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 lesSalaries; + } + + public User lireSalarie(String log, String m){ + User leSalarie=new User(); + ResultSet resultQ = null; + try{ + + PreparedStatement prepStmt = null; + + String sql = "SELECT * FROM Salarie WHERE login = ? AND mdp=?"; + prepStmt = laConnection.prepareStatement(sql); // pré-compilation + + prepStmt.setString(1, log); //le param. 1 est remplacé par "Toto" + prepStmt.setString(2,m); + resultQ = prepStmt.executeQuery(); + if (resultQ.first()){ + leSalarie.setLogin(resultQ.getString("login")); + leSalarie.setId(resultQ.getInt("idSal")); + leSalarie.setMdp(resultQ.getString("mdp")); + leSalarie.setRole(resultQ.getBoolean("role")); + } + resultQ.close(); + prepStmt.close(); + }catch (SQLException ex){ + System.out.println("SQLException : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return leSalarie; + } +} diff --git a/src/java/gestionClient/ListeServlet2.java b/src/java/gestionClient/ListeServlet2.java index 20307cd..3e3f2cc 100644 --- a/src/java/gestionClient/ListeServlet2.java +++ b/src/java/gestionClient/ListeServlet2.java @@ -1,93 +1,92 @@ -/* - * 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(); - - - 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"; - }// - -} +/* + * 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(); + //envoyer à la vue la liste des clients + 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 index 5d6c96e..9b059ce 100644 --- a/src/java/gestionClient/NouveauServlet.java +++ b/src/java/gestionClient/NouveauServlet.java @@ -1,112 +1,112 @@ -/* - * 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 jakarta.servlet.http.HttpSession; -import java.util.ArrayList; -import testForms.AuthentifForm; -import testForms.NouveauClientForm; - -/** - * - * @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); - //Création de l'objet leControl de type AuthentifForm - NouveauClientForm leControle = new NouveauClientForm(); - //Appel de la méthode controlerAdmin - int isNum=leControle.verifierClient(request); - //création de 2 attributs de requête (isAdmin et leControle) - request.setAttribute("controlForm", leControle); - request.setAttribute("isNumAjoute", isNum); - //gestion de la liste des clients créés - if (isNum != -1) { - // Ajout du no du client créé, dans une collection d’entiers stockée en session - // 1, Récupération de la session - HttpSession maSession = request.getSession(); - // 2. Récupération de la collection des clients si elle existe, création sinon - ArrayList lesNouveauxClients = (ArrayList) maSession.getAttribute("lesNvxClients"); - if (lesNouveauxClients == null) { - lesNouveauxClients = new ArrayList<>(); - } - // 3. Ajout du no du client créé dans la collection - lesNouveauxClients.add(isNum); - // 4. Mise à jour de la session - maSession.setAttribute("lesNvxClients", lesNouveauxClients); } - //Affichage JSP, redirection couche vue - getServletContext().getRequestDispatcher("/WEB-INF/nouveauClientVue.jsp").forward(request, response); - } - - /** - * Returns a short description of the servlet. - * - * @return a String containing servlet description - */ - @Override - public String getServletInfo() { - return "Short description"; - }// - -} +/* + * 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 jakarta.servlet.http.HttpSession; +import java.util.ArrayList; +import testForms.AuthentifForm; +import testForms.NouveauClientForm; + +/** + * + * @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 { + // 1, Récupération de la session + HttpSession maSession = request.getSession(); + //Création de l'objet leControl de type AuthentifForm + NouveauClientForm leControle = new NouveauClientForm(); + //Appel de la méthode créer le client dans la BD + int isNum=leControle.verifierClient(request); + //création de 2 attributs de requête (isAdmin et leControle) + request.setAttribute("controlForm", leControle); + request.setAttribute("isNumAjoute", isNum); + //gestion de la liste des clients créés + if (isNum != -1) { + // Ajout du no du client créé, dans une collection d’entiers stockée en session + // 2. Récupération de la collection des clients si elle existe, création sinon + ArrayList lesNouveauxClients = (ArrayList) maSession.getAttribute("lesNvxClients"); + if (lesNouveauxClients == null) { + lesNouveauxClients = new ArrayList<>(); + } + // 3. Ajout du no du client créé dans la collection + lesNouveauxClients.add(isNum); + // 4. Mise à jour de la session + maSession.setAttribute("lesNvxClients", lesNouveauxClients); + } + //Affichage JSP, redirection couche vue + getServletContext().getRequestDispatcher("/WEB-INF/nouveauClientVue.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/web/WEB-INF/listeClientsVue.jsp b/web/WEB-INF/listeClientsVue.jsp index f019662..196becf 100644 --- a/web/WEB-INF/listeClientsVue.jsp +++ b/web/WEB-INF/listeClientsVue.jsp @@ -13,12 +13,12 @@ Liste des clients - + <%@include file="jspf/enteteClient.jspf" %> <%@include file="jspf/menuClient.jspf" %>

Liste des clients

- + <%--Affichage de la vue--%> - +