This commit is contained in:
2
src/conf/MANIFEST.MF
Normal file
2
src/conf/MANIFEST.MF
Normal file
@@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
|
||||
68
src/java/bdd/Connexion.java
Normal file
68
src/java/bdd/Connexion.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author clementine.desrucques
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
122
src/java/bdd/PompierMySql.java
Normal file
122
src/java/bdd/PompierMySql.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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 com.test.beans.Pompier;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author clementine.desrucques
|
||||
*/
|
||||
public class PompierMySql {
|
||||
|
||||
private Connection theConnection;
|
||||
private Pompier unPompier;
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
*/
|
||||
public PompierMySql() {
|
||||
theConnection = Connexion.getConnect("localhost", //s erveur
|
||||
"sdis29", // base de données
|
||||
"admin",// user
|
||||
"minda"); // mot de passe ClientMysql() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creation du client passé en paramètre dans la table client
|
||||
* Requête non préparée
|
||||
* @param c objet de type Client (sans identifiant)
|
||||
* @return int : id du client créé
|
||||
*/
|
||||
public int create(Pompier p) {
|
||||
int id = -1;
|
||||
try {
|
||||
Statement stmt = theConnection.createStatement();
|
||||
int status = stmt.executeUpdate(
|
||||
"INSERT INTO pompier (idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade) "
|
||||
+ "VALUES ('" + p.getIdCaserne() + "', '"
|
||||
+ p.getNom() + "', '"
|
||||
+ p.getPrenom() + "', '"
|
||||
+ p.getStatut() + "', "
|
||||
+ p.getMail() + ", '"
|
||||
+ p.getLogin() + ", '"
|
||||
+ p.getMdp() + ", '"
|
||||
+ p.getAdrNo() + ", '"
|
||||
+ p.getAdrRue() + "', '"
|
||||
+ p.getAdrCP() + "', '"
|
||||
+ p.getAdrVille() + "', '"
|
||||
+ p.getGrade()+ "' );",
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
// Recherche de l'identifiant du pompier créé
|
||||
if (status > 0) {
|
||||
ResultSet result = stmt.getGeneratedKeys();
|
||||
if (result.first()) {
|
||||
id = result.getInt(1);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("SQLException : " + ex.getMessage());
|
||||
System.out.println("SQLState : " + ex.getSQLState());
|
||||
System.out.println("Code erreur : " + ex.getErrorCode());
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creation du client passé en paramètre dans la table client
|
||||
* Requête préparée
|
||||
* @param c objet de type Client (sans identifiant)
|
||||
* @return int : id du client créé
|
||||
*/
|
||||
public int createRP(Pompier p) {
|
||||
int id = -1;
|
||||
try {
|
||||
PreparedStatement stmt = null;
|
||||
String sql = "INSERT INTO pompier(idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);";
|
||||
stmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
stmt.setInt(1, p.getIdCaserne());
|
||||
stmt.setString(2, p.getNom());
|
||||
stmt.setString(3, p.getPrenom());
|
||||
stmt.setInt(4, p.getStatut());
|
||||
stmt.setString(5,p.getMail() );
|
||||
stmt.setString(6,p.getLogin() );
|
||||
stmt.setString(7,p.getMdp() );
|
||||
stmt.setInt(8, p.getAdrNo());
|
||||
stmt.setString(9, p.getAdrRue());
|
||||
stmt.setString(10, p.getAdrCP());
|
||||
stmt.setString(11, p.getAdrVille());
|
||||
stmt.setInt(12, p.getGrade());
|
||||
|
||||
System.out.println("Requête : " + stmt.toString());
|
||||
int status = stmt.executeUpdate();
|
||||
|
||||
|
||||
// Recherche de l'identifiant du client créé
|
||||
if (status > 0) {
|
||||
ResultSet result = stmt.getGeneratedKeys();
|
||||
if (result.first()) {
|
||||
id = result.getInt(1);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("SQLException : " + ex.getMessage());
|
||||
System.out.println("SQLState : " + ex.getSQLState());
|
||||
System.out.println("Code erreur : " + ex.getErrorCode());
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
233
src/java/com/test/beans/Pompier.java
Normal file
233
src/java/com/test/beans/Pompier.java
Normal file
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* 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 clementine.desrucques
|
||||
*/
|
||||
public class Pompier {
|
||||
private int id;
|
||||
private int idCaserne;
|
||||
private String nom;
|
||||
private String prenom;
|
||||
private int statut;
|
||||
private String mail;
|
||||
private String login;
|
||||
private String mdp;
|
||||
private int adrNo;
|
||||
private String adrRue;
|
||||
private String adrCP;
|
||||
private String adrVille;
|
||||
private int grade;
|
||||
|
||||
public Pompier(int id, int idCaserne, String nom, String prenom, int statut, String mail, String login, String mdp, int adrNo, String adrRue, String adrCP, String adrVille, int grade) {
|
||||
this(idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade);
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Pompier(int idCaserne, String nom, String prenom, int statut, String mail, String login, String mdp, int adrNo, String adrRue, String adrCP, String adrVille, int grade) {
|
||||
this.idCaserne = idCaserne;
|
||||
this.nom = nom;
|
||||
this.prenom = prenom;
|
||||
this.statut = statut;
|
||||
this.mail = mail;
|
||||
this.login = login;
|
||||
this.mdp = mdp;
|
||||
this.adrNo = adrNo;
|
||||
this.adrRue = adrRue;
|
||||
this.adrCP = adrCP;
|
||||
this.adrVille = adrVille;
|
||||
this.grade = grade;
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getIdCaserne() {
|
||||
return idCaserne;
|
||||
}
|
||||
|
||||
public void setIdCaserne(int idCaserne) {
|
||||
this.idCaserne = idCaserne;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public String getPrenom() {
|
||||
return prenom;
|
||||
}
|
||||
|
||||
public void setPrenom(String prenom) {
|
||||
this.prenom = prenom;
|
||||
}
|
||||
|
||||
public int getStatut() {
|
||||
return statut;
|
||||
}
|
||||
|
||||
public void setStatut(int statut) {
|
||||
this.statut = statut;
|
||||
}
|
||||
|
||||
public String getMail() {
|
||||
return mail;
|
||||
}
|
||||
|
||||
public void setMail(String mail) {
|
||||
this.mail = mail;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getMdp() {
|
||||
return mdp;
|
||||
}
|
||||
|
||||
public void setMdp(String mdp) {
|
||||
this.mdp = mdp;
|
||||
}
|
||||
|
||||
public int getAdrNo() {
|
||||
return adrNo;
|
||||
}
|
||||
|
||||
public void setAdrNo(int adrNo) {
|
||||
this.adrNo = adrNo;
|
||||
}
|
||||
|
||||
public String getAdrRue() {
|
||||
return adrRue;
|
||||
}
|
||||
|
||||
public void setAdrRue(String adrRue) {
|
||||
this.adrRue = adrRue;
|
||||
}
|
||||
|
||||
public String getAdrCP() {
|
||||
return adrCP;
|
||||
}
|
||||
|
||||
public void setAdrCP(String adrCP) {
|
||||
this.adrCP = adrCP;
|
||||
}
|
||||
|
||||
public String getAdrVille() {
|
||||
return adrVille;
|
||||
}
|
||||
|
||||
public void setAdrVille(String adrVille) {
|
||||
this.adrVille = adrVille;
|
||||
}
|
||||
|
||||
public int getGrade() {
|
||||
return grade;
|
||||
}
|
||||
|
||||
public void setGrade(int grade) {
|
||||
this.grade = grade;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 29 * hash + this.id;
|
||||
hash = 29 * hash + this.idCaserne;
|
||||
hash = 29 * hash + Objects.hashCode(this.nom);
|
||||
hash = 29 * hash + Objects.hashCode(this.prenom);
|
||||
hash = 29 * hash + this.statut;
|
||||
hash = 29 * hash + Objects.hashCode(this.mail);
|
||||
hash = 29 * hash + Objects.hashCode(this.login);
|
||||
hash = 29 * hash + Objects.hashCode(this.mdp);
|
||||
hash = 29 * hash + this.adrNo;
|
||||
hash = 29 * hash + Objects.hashCode(this.adrRue);
|
||||
hash = 29 * hash + Objects.hashCode(this.adrCP);
|
||||
hash = 29 * hash + Objects.hashCode(this.adrVille);
|
||||
hash = 29 * hash + this.grade;
|
||||
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 Pompier other = (Pompier) obj;
|
||||
if (this.id != other.id) {
|
||||
return false;
|
||||
}
|
||||
if (this.idCaserne != other.idCaserne) {
|
||||
return false;
|
||||
}
|
||||
if (this.statut != other.statut) {
|
||||
return false;
|
||||
}
|
||||
if (this.adrNo != other.adrNo) {
|
||||
return false;
|
||||
}
|
||||
if (this.grade != other.grade) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.nom, other.nom)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.prenom, other.prenom)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.mail, other.mail)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.login, other.login)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.mdp, other.mdp)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.adrRue, other.adrRue)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.adrCP, other.adrCP)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.adrVille, other.adrVille)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Pompier{" + "id=" + id + ", idCaserne=" + idCaserne + ", nom=" + nom + ", prenom=" + prenom + ", statut=" + statut + ", mail=" + mail + ", login=" + login + ", mdp=" + mdp + ", adrNo=" + adrNo + ", adrRue=" + adrRue + ", adrCP=" + adrCP + ", adrVille=" + adrVille + ", grade=" + grade + '}';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
68
src/java/com/test/beans/User.java
Normal file
68
src/java/com/test/beans/User.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 clementine.desrucques
|
||||
*/
|
||||
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 void setPseudo(String pseudo) {
|
||||
this.pseudo = pseudo;
|
||||
}
|
||||
|
||||
public String getMdp() {
|
||||
return mdp;
|
||||
}
|
||||
|
||||
public void setMdp(String mdp) {
|
||||
this.mdp = mdp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 67 * hash + Objects.hashCode(this.pseudo);
|
||||
hash = 67 * 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;
|
||||
}
|
||||
|
||||
}
|
||||
55
src/java/com/test/forms/AuthentifForm.java
Normal file
55
src/java/com/test/forms/AuthentifForm.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.forms;
|
||||
|
||||
import com.test.beans.User;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
/**
|
||||
*
|
||||
* @author clementine.desrucques
|
||||
*/
|
||||
public class AuthentifForm {
|
||||
private String resultat;
|
||||
|
||||
public String getResultat() {
|
||||
return resultat;
|
||||
}
|
||||
|
||||
public void setResultat(String resultat) {
|
||||
this.resultat = resultat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contôle si les paramètres ztPseudo et ztMDP passé dans request
|
||||
* correspondent à ceux de l'addministrateur Mise à jour de l'attribut
|
||||
* resultat
|
||||
*
|
||||
* @param request
|
||||
* @return true is ok, false sinon
|
||||
*/
|
||||
public boolean controlerRole(HttpServletRequest request) {
|
||||
/* Comparaison entre l'utilisateur admin et un utilisateur créé
|
||||
avec le pseudo et le mdp saisi */
|
||||
User ChefCaserne = new User("Michel", "mRANN");
|
||||
User userSaisi = new User( request.getParameter("ztPseudo"),
|
||||
request.getParameter("ztMDP"));
|
||||
boolean isChef = userSaisi.equals(ChefCaserne);
|
||||
|
||||
// Mise à jour de l'attribut resultat
|
||||
setResultat(isChef ? "Vous êtes chef de caserne" : "Vous n'êtes pas chef de caserne");
|
||||
|
||||
return isChef;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
76
src/java/com/test/forms/NouveauPompForm.java
Normal file
76
src/java/com/test/forms/NouveauPompForm.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.forms;
|
||||
|
||||
import bdd.PompierMySql;
|
||||
import com.mysql.cj.util.StringUtils;
|
||||
import com.test.beans.Pompier;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.Enumeration;
|
||||
import static jdk.vm.ci.sparc.SPARC.CPUFeature.MD5;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author clementine.desrucques
|
||||
*/
|
||||
public class NouveauPompForm {
|
||||
String message="";
|
||||
|
||||
public int verifNouveauPompier(HttpServletRequest request) {
|
||||
|
||||
// Contrôle du no de rue qui doit être numérique
|
||||
String noRueString = request.getParameter("nAdrNo");
|
||||
boolean isNumeric = StringUtils.isStrictlyNumeric(noRueString);
|
||||
if (!isNumeric) {
|
||||
message = "Le no de rue doit être numérique";
|
||||
return -1;
|
||||
}
|
||||
int noRue = Integer.parseInt(noRueString);
|
||||
|
||||
// Contrôle car "<" dans les zones de texte
|
||||
//String [] lesSaisies = request.getParameterValues(noRueString); // Valeurs saisies
|
||||
Enumeration lesNoms = request.getParameterNames();
|
||||
int erreur = 0;
|
||||
while (erreur ==0 && lesNoms.hasMoreElements()) {
|
||||
Object paramObjet=lesNoms.nextElement();
|
||||
String param=(String)paramObjet;
|
||||
String value=request.getParameter(param);
|
||||
if (value.contains("<")) {
|
||||
message = "Veullez recommencer votre saisie, une anomalie sur une zone de saisie a été détectée ";
|
||||
erreur=1;
|
||||
}
|
||||
}
|
||||
if (erreur > 0) return -1;
|
||||
|
||||
// Creation d'un objet de type Client avec les données transmises
|
||||
// String mdpChiffre = MD5.encode(request.getParameter("ztMDP"));
|
||||
Pompier unPompier = new Pompier(request.getParameter("id"),
|
||||
request.getParameter("idCaserne"),
|
||||
request.getParameter("ztNom"),
|
||||
request.getParameter("ztPrenom"),
|
||||
request.getParameter("nStatut"),
|
||||
request.getParameter("eMail"),
|
||||
request.getParameter("ztLogin"),
|
||||
request.getParameter("ztMDP"),
|
||||
noRue,
|
||||
request.getParameter("ztAdrRue"),
|
||||
request.getParameter("ztAdrCP"),
|
||||
request.getParameter("ztAdrVille"),
|
||||
request.getParameter("nGrade")
|
||||
);
|
||||
PompierMySql cm = new PompierMySql();
|
||||
int id = cm.createRP(unPompier); // Requête préparée
|
||||
if (id == -1) {
|
||||
message = "Erreur lors de la création du pompier";
|
||||
}
|
||||
return id;
|
||||
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
86
src/java/com/test/servlets/ChefCaserneServlet.java
Normal file
86
src/java/com/test/servlets/ChefCaserneServlet.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 funcha.ahamadi
|
||||
*/
|
||||
public class ChefCaserneServlet 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 ChefCaserneServlet</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Servlet ChefCaserneServlet 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>
|
||||
|
||||
}
|
||||
86
src/java/com/test/servlets/PompierServlet.java
Normal file
86
src/java/com/test/servlets/PompierServlet.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 funcha.ahamadi
|
||||
*/
|
||||
public class PompierServlet 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 PompierServlet</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Servlet PompierServlet 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>
|
||||
|
||||
}
|
||||
109
src/java/com/test/servlets/authentifServlet.java
Normal file
109
src/java/com/test/servlets/authentifServlet.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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 com.test.forms.AuthentifForm;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author clementine.desrucques
|
||||
*/
|
||||
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 AccueilServlet</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Servlet AccueilServlet 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);
|
||||
System.out.println("****blablabla****");
|
||||
HttpSession maSession = request.getSession();
|
||||
maSession.removeAttribute("isAuthentified");
|
||||
getServletContext().getRequestDispatcher("/WEB-INF/accueilJSP.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 {
|
||||
// Création de l'objet leControle de type AuthentifForm
|
||||
AuthentifForm leControle = new AuthentifForm();
|
||||
// Appel de la méthode controlerAdmin
|
||||
boolean isChef = leControle.controlerRole(request);
|
||||
// Création de 2 attributs de requête (isAdmin et leControle)
|
||||
request.setAttribute("isChef", isChef);
|
||||
request.setAttribute("controlForm", leControle);
|
||||
HttpSession maSession = request.getSession();
|
||||
maSession.setAttribute("isAuthentified", true);
|
||||
// Affichage de la JSP
|
||||
if(isChef==true){
|
||||
getServletContext().getRequestDispatcher("/WEB-INF/ChefCaserneJSP.jsp")
|
||||
.forward(request, response);
|
||||
}else{
|
||||
getServletContext().getRequestDispatcher("/WEB-INF/PompierJSP.jsp")
|
||||
.forward(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a short description of the servlet.
|
||||
*
|
||||
* @return a String containing servlet description
|
||||
*/
|
||||
@Override
|
||||
public String getServletInfo() {
|
||||
return "Short description";
|
||||
}// </editor-fold>
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user