From 04000480a543254b0e44efcc847e1b61693397ee Mon Sep 17 00:00:00 2001 From: "steve.maingana" Date: Mon, 15 Sep 2025 17:43:29 +0200 Subject: [PATCH] First commit --- nb-configuration.xml | 18 +++ pom.xml | 42 +++++++ .../JakartaRestConfiguration.java | 13 ++ .../resources/JakartaEE10Resource.java | 20 ++++ .../com/test/servlets/AccueilServlet.java | 113 ++++++++++++++++++ .../java/com/test/servlets/ListeServlet.java | 90 ++++++++++++++ .../com/test/servlets/NouveauServlet.java | 90 ++++++++++++++ src/main/resources/META-INF/persistence.xml | 7 ++ src/main/webapp/WEB-INF/accueilVue.jsp | 27 +++++ src/main/webapp/WEB-INF/beans.xml | 6 + src/main/webapp/WEB-INF/jspf/entete.jspf | 7 ++ src/main/webapp/WEB-INF/jspf/login.jspf | 6 + src/main/webapp/WEB-INF/jspf/menu.jspf | 9 ++ src/main/webapp/WEB-INF/listeClientsVue.jsp | 16 +++ src/main/webapp/WEB-INF/nouveauClientVue.jsp | 16 +++ src/main/webapp/WEB-INF/web.xml | 32 +++++ src/main/webapp/index.html | 10 ++ src/main/webapp/style/style.css | 12 ++ 18 files changed, 534 insertions(+) create mode 100644 nb-configuration.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/mycompany/test2jakarta/JakartaRestConfiguration.java create mode 100644 src/main/java/com/mycompany/test2jakarta/resources/JakartaEE10Resource.java create mode 100644 src/main/java/com/test/servlets/AccueilServlet.java create mode 100644 src/main/java/com/test/servlets/ListeServlet.java create mode 100644 src/main/java/com/test/servlets/NouveauServlet.java create mode 100644 src/main/resources/META-INF/persistence.xml create mode 100644 src/main/webapp/WEB-INF/accueilVue.jsp create mode 100644 src/main/webapp/WEB-INF/beans.xml create mode 100644 src/main/webapp/WEB-INF/jspf/entete.jspf create mode 100644 src/main/webapp/WEB-INF/jspf/login.jspf create mode 100644 src/main/webapp/WEB-INF/jspf/menu.jspf create mode 100644 src/main/webapp/WEB-INF/listeClientsVue.jsp create mode 100644 src/main/webapp/WEB-INF/nouveauClientVue.jsp create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/index.html create mode 100644 src/main/webapp/style/style.css diff --git a/nb-configuration.xml b/nb-configuration.xml new file mode 100644 index 0000000..4da1f6c --- /dev/null +++ b/nb-configuration.xml @@ -0,0 +1,18 @@ + + + + + + ide + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..60cfac0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + com.mycompany + Test2Jakarta + 1.0-SNAPSHOT + war + Test2Jakarta-1.0-SNAPSHOT + + + UTF-8 + 10.0.0 + + + + + jakarta.platform + jakarta.jakartaee-api + ${jakartaee} + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + 11 + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + + \ No newline at end of file diff --git a/src/main/java/com/mycompany/test2jakarta/JakartaRestConfiguration.java b/src/main/java/com/mycompany/test2jakarta/JakartaRestConfiguration.java new file mode 100644 index 0000000..14695f8 --- /dev/null +++ b/src/main/java/com/mycompany/test2jakarta/JakartaRestConfiguration.java @@ -0,0 +1,13 @@ +package com.mycompany.test2jakarta; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +/** + * Configures Jakarta RESTful Web Services for the application. + * @author Juneau + */ +@ApplicationPath("resources") +public class JakartaRestConfiguration extends Application { + +} diff --git a/src/main/java/com/mycompany/test2jakarta/resources/JakartaEE10Resource.java b/src/main/java/com/mycompany/test2jakarta/resources/JakartaEE10Resource.java new file mode 100644 index 0000000..f084c4a --- /dev/null +++ b/src/main/java/com/mycompany/test2jakarta/resources/JakartaEE10Resource.java @@ -0,0 +1,20 @@ +package com.mycompany.test2jakarta.resources; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Response; + +/** + * + * @author + */ +@Path("jakartaee10") +public class JakartaEE10Resource { + + @GET + public Response ping(){ + return Response + .ok("ping Jakarta EE") + .build(); + } +} diff --git a/src/main/java/com/test/servlets/AccueilServlet.java b/src/main/java/com/test/servlets/AccueilServlet.java new file mode 100644 index 0000000..7eff23f --- /dev/null +++ b/src/main/java/com/test/servlets/AccueilServlet.java @@ -0,0 +1,113 @@ +/* + * 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 com.test.servlets; + +import jakarta.servlet.RequestDispatcher; +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 steve.maingana + */ + +@WebServlet(name = "AccueilServlet", urlPatterns = {"/"}) + +public class AccueilServlet extends HttpServlet { + String monPseudo = "steve.mngn"; + String monMdp = "1234"; + /** + * 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 Test2Jakarta"); + out.println(""); + out.println(""); + out.println("

Servlet Test2Jakarta 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); + + + String pseudo = request.getParameter("pseudo"); + String mdp = request.getParameter("mdp"); + if ((pseudo != null && !pseudo.isBlank()) || (mdp != null && !mdp.isBlank())) { + request.setAttribute("login", false); + } else if (!pseudo.equals(this.monPseudo) && !mdp.equals(this.monMdp)) { + request.setAttribute("login", false); + } else { + request.setAttribute("login", true); + } + + + RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/accueilVue.jsp"); + dispatcher.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); + + String pseudo = request.getParameter("pseudo"); + String mdp = request.getParameter("mdp"); + if (pseudo.equals(this.monPseudo) && mdp.equals(this.monMdp)) { + request.setAttribute("login", true); + request.setAttribute("pseudo", pseudo); + } + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/src/main/java/com/test/servlets/ListeServlet.java b/src/main/java/com/test/servlets/ListeServlet.java new file mode 100644 index 0000000..f7ebb6e --- /dev/null +++ b/src/main/java/com/test/servlets/ListeServlet.java @@ -0,0 +1,90 @@ +/* + * 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 com.test.servlets; + +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 steve.maingana + */ + +@WebServlet(name = "ListeServlet", urlPatterns = {"/ListeClients"}) + +public class ListeServlet 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 ListeServlet"); + out.println(""); + out.println(""); + out.println("

Servlet ListeServlet 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/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/main/java/com/test/servlets/NouveauServlet.java b/src/main/java/com/test/servlets/NouveauServlet.java new file mode 100644 index 0000000..13705fc --- /dev/null +++ b/src/main/java/com/test/servlets/NouveauServlet.java @@ -0,0 +1,90 @@ +/* + * 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 com.test.servlets; + +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 steve.maingana + */ + +@WebServlet(name = "NouveauServlet", urlPatterns = {"/NouveauClient"}) + +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 { + // processRequest(request, response); + 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/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..7582bf1 --- /dev/null +++ b/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/main/webapp/WEB-INF/accueilVue.jsp b/src/main/webapp/WEB-INF/accueilVue.jsp new file mode 100644 index 0000000..7ff896c --- /dev/null +++ b/src/main/webapp/WEB-INF/accueilVue.jsp @@ -0,0 +1,27 @@ +<%-- + Document : accueilJSP + Created on : 12 sept. 2025, 14:42:44 + Author : steve.maingana +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + <%@include file="jspf/entete.jspf" %> + + <%@include file="jspf/menu.jspf" %> +

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

+ <% + boolean login = (boolean) request.getAttribute("login"); + if (login) { + %> +

Bienvenue ${pseudo}

+ <% + } else { + %> + <%@include file="jspf/login.jspf" %> + <% + } + %> + + diff --git a/src/main/webapp/WEB-INF/beans.xml b/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..9dfae34 --- /dev/null +++ b/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jspf/entete.jspf b/src/main/webapp/WEB-INF/jspf/entete.jspf new file mode 100644 index 0000000..26e72a2 --- /dev/null +++ b/src/main/webapp/WEB-INF/jspf/entete.jspf @@ -0,0 +1,7 @@ +<%-- any content can be specified here e.g.: --%> +<%@ page pageEncoding="UTF-8" %> + + + Gestion des clients + + diff --git a/src/main/webapp/WEB-INF/jspf/login.jspf b/src/main/webapp/WEB-INF/jspf/login.jspf new file mode 100644 index 0000000..d64c3c6 --- /dev/null +++ b/src/main/webapp/WEB-INF/jspf/login.jspf @@ -0,0 +1,6 @@ +<%-- any content can be specified here e.g.: --%> +<%@ page pageEncoding="UTF-8" %> +
+ + +
diff --git a/src/main/webapp/WEB-INF/jspf/menu.jspf b/src/main/webapp/WEB-INF/jspf/menu.jspf new file mode 100644 index 0000000..beb8464 --- /dev/null +++ b/src/main/webapp/WEB-INF/jspf/menu.jspf @@ -0,0 +1,9 @@ +<%-- any content can be specified here e.g.: --%> +<%@ page pageEncoding="UTF-8" %> + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/listeClientsVue.jsp b/src/main/webapp/WEB-INF/listeClientsVue.jsp new file mode 100644 index 0000000..7db3511 --- /dev/null +++ b/src/main/webapp/WEB-INF/listeClientsVue.jsp @@ -0,0 +1,16 @@ +<%-- + Document : listeClientsJSP + Created on : 12 sept. 2025, 14:43:13 + Author : steve.maingana +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + <%@include file="jspf/entete.jspf" %> + + <%@include file="jspf/menu.jspf" %> +

Liste des clients

+

Page en construction

+ + diff --git a/src/main/webapp/WEB-INF/nouveauClientVue.jsp b/src/main/webapp/WEB-INF/nouveauClientVue.jsp new file mode 100644 index 0000000..43f6400 --- /dev/null +++ b/src/main/webapp/WEB-INF/nouveauClientVue.jsp @@ -0,0 +1,16 @@ +<%-- + Document : nouveauClientJSP + Created on : 12 sept. 2025, 14:42:54 + Author : steve.maingana +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + <%@include file="jspf/entete.jspf" %> + + <%@include file="jspf/menu.jspf" %> +

Création d’un nouveau client

+

Page en construction

+ + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..6a94390 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,32 @@ + + + + AccueilServlet + com.test.servlets.AccueilServlet + + + NouveauServlet + com.test.servlets.NouveauServlet + + + ListeServlet + com.test.servlets.ListeServlet + + + AccueilServlet + / + + + NouveauServlet + /NouveauClient + + + ListeServlet + /ListeClients + + + + 30 + + + diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html new file mode 100644 index 0000000..3368e9c --- /dev/null +++ b/src/main/webapp/index.html @@ -0,0 +1,10 @@ + + + + Start Page + + + +

Hello World!

+ + diff --git a/src/main/webapp/style/style.css b/src/main/webapp/style/style.css new file mode 100644 index 0000000..238a03b --- /dev/null +++ b/src/main/webapp/style/style.css @@ -0,0 +1,12 @@ +/* +Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license +Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/CascadeStyleSheet.css to edit this template +*/ +/* + Created on : 15 sept. 2025, 14:59:25 + Author : steve.maingana +*/ + +body { + background-color: red; +} \ No newline at end of file