This commit is contained in:
parent
a954e7165a
commit
f008779cbe
@ -983,11 +983,15 @@ exists or setup the property manually. For example like this:
|
||||
<target depends="init,compile,compile-jsps,-pre-dist,-do-dist-with-manifest,-do-dist-without-manifest" name="do-dist"/>
|
||||
<target depends="init" if="dist.ear.dir" name="library-inclusion-in-manifest">
|
||||
<copyfiles files="${file.reference.mysql-connector-java-8.0.26.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
|
||||
<copyfiles files="${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
|
||||
<copyfiles files="${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
|
||||
<mkdir dir="${build.web.dir}/META-INF"/>
|
||||
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
|
||||
</target>
|
||||
<target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir">
|
||||
<copyfiles files="${file.reference.mysql-connector-java-8.0.26.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
|
||||
<copyfiles files="${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
|
||||
<copyfiles files="${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
|
||||
</target>
|
||||
<target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
|
||||
<delete dir="${build.web.dir}/WEB-INF/lib"/>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -10,6 +10,14 @@
|
||||
<file>${file.reference.mysql-connector-java-8.0.26.jar}</file>
|
||||
<path-in-war>WEB-INF/lib</path-in-war>
|
||||
</library>
|
||||
<library dirs="200">
|
||||
<file>${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar}</file>
|
||||
<path-in-war>WEB-INF/lib</path-in-war>
|
||||
</library>
|
||||
<library dirs="200">
|
||||
<file>${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar}</file>
|
||||
<path-in-war>WEB-INF/lib</path-in-war>
|
||||
</library>
|
||||
</web-module-libraries>
|
||||
<web-module-additional-libraries/>
|
||||
<source-roots>
|
||||
|
22
src/java/bdd/ClientMysql.java
Normal file
22
src/java/bdd/ClientMysql.java
Normal file
@ -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");
|
||||
}
|
||||
}
|
62
src/java/bdd/Connexion.java
Normal file
62
src/java/bdd/Connexion.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
62
src/java/com/test/beans/User.java
Normal file
62
src/java/com/test/beans/User.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
87
src/java/com/test/servlets/AuthentifServlet.java
Normal file
87
src/java/com/test/servlets/AuthentifServlet.java
Normal file
@ -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 <code>GET</code> and <code>POST</code>
|
||||
* 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("<!DOCTYPE html>");
|
||||
out.println("<html>");
|
||||
out.println("<head>");
|
||||
out.println("<title>Servlet AuthentifServlet</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Servlet AuthentifServlet at " + request.getContextPath() + "</h1>");
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
}
|
||||
}
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
|
||||
/**
|
||||
* Handles the HTTP <code>GET</code> 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 <code>POST</code> 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";
|
||||
}// </editor-fold>
|
||||
|
||||
}
|
87
src/java/com/test/servlets/ModifServlet.java
Normal file
87
src/java/com/test/servlets/ModifServlet.java
Normal file
@ -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 <code>GET</code> and <code>POST</code>
|
||||
* 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("<!DOCTYPE html>");
|
||||
out.println("<html>");
|
||||
out.println("<head>");
|
||||
out.println("<title>Servlet ModifServlet</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Servlet ModifServlet at " + request.getContextPath() + "</h1>");
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
}
|
||||
}
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
|
||||
/**
|
||||
* Handles the HTTP <code>GET</code> 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 <code>POST</code> 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";
|
||||
}// </editor-fold>
|
||||
|
||||
}
|
87
src/java/com/test/servlets/ProfilServlet.java
Normal file
87
src/java/com/test/servlets/ProfilServlet.java
Normal file
@ -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 <code>GET</code> and <code>POST</code>
|
||||
* 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("<!DOCTYPE html>");
|
||||
out.println("<html>");
|
||||
out.println("<head>");
|
||||
out.println("<title>Servlet ProfilServlet</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Servlet ProfilServlet at " + request.getContextPath() + "</h1>");
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
}
|
||||
}
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
|
||||
/**
|
||||
* Handles the HTTP <code>GET</code> 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 <code>POST</code> 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";
|
||||
}// </editor-fold>
|
||||
|
||||
}
|
28
web/WEB-INF/web.xml
Normal file
28
web/WEB-INF/web.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
|
||||
<servlet>
|
||||
<servlet-name>AuthentifServlet</servlet-name>
|
||||
<servlet-class>com.test.servlets.AuthentifServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>ModifServlet</servlet-name>
|
||||
<servlet-class>com.test.servlets.ModifServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>ProfilServlet</servlet-name>
|
||||
<servlet-class>com.test.servlets.ProfilServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>AuthentifServlet</servlet-name>
|
||||
<url-pattern>/authentif</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>ModifServlet</servlet-name>
|
||||
<url-pattern>/Modif</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>ProfilServlet</servlet-name>
|
||||
<url-pattern>/Profil</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
Loading…
x
Reference in New Issue
Block a user