diff --git a/src/java/com/test/servlets/CreaPompierServlet.java b/src/java/com/test/servlets/CreaPompierServlet.java new file mode 100644 index 0000000..43a32f2 --- /dev/null +++ b/src/java/com/test/servlets/CreaPompierServlet.java @@ -0,0 +1,106 @@ +/* + * 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.NouveauPompForm; +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.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + + +/** + * + * @author clementine.desrucques + */ +public class CreaPompierServlet 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 CreaPompierServlet"); + out.println(""); + out.println(""); + out.println("

Servlet CreaPompierServlet 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/CreaPompier.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 { + NouveauPompForm nvp = new NouveauPompForm(); + int idPomp = nvp.verifNouveauPompier(request); + request.setAttribute("idPompier", idPomp); + request.setAttribute("message", nvp.getMessage()); + + if (idPomp != -1){ + HttpSession maSession = request.getSession(); + ArrayList lesNouveauxPompiers = (ArrayList) maSession.getAttribute("lesNvxPompiers"); + if (lesNouveauxPompiers == null){ + lesNouveauxPompiers = new ArrayList<>(); + } + lesNouveauxPompiers.add(idPomp); + maSession.setAttribute("lesNvxPompiers", lesNouveauxPompiers); + } + + getServletContext().getRequestDispatcher("/WEB-INF/CreaPompier.jsp").forward(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/src/java/com/test/servlets/ModifPompierServlet.java b/src/java/com/test/servlets/ModifPompierServlet.java new file mode 100644 index 0000000..42d34d8 --- /dev/null +++ b/src/java/com/test/servlets/ModifPompierServlet.java @@ -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 jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + + +/** + * + * @author clementine.desrucques + */ +public class ModifPompierServlet 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 ModifPompierServlet"); + out.println(""); + out.println(""); + out.println("

Servlet ModifPompierServlet at " + request.getContextPath() + "

"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * 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/ChefCaserneJSP.jsp b/web/WEB-INF/ChefCaserneJSP.jsp index b6b4772..9ec9a4f 100644 --- a/web/WEB-INF/ChefCaserneJSP.jsp +++ b/web/WEB-INF/ChefCaserneJSP.jsp @@ -54,6 +54,7 @@
- + + diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index b9d7f13..e8aa329 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -12,6 +12,14 @@ authentifServlet com.test.servlets.authentifServlet + + ModifPompierServlet + com.test.servlets.ModifPompierServlet + + + CreaPompierServlet + com.test.servlets.CreaPompierServlet + PompierServlet /Pompier @@ -24,6 +32,14 @@ authentifServlet /Authentification + + ModifPompierServlet + /ModifPompier + + + CreaPompierServlet + /CreaPompier + 30