This commit is contained in:
parent
78e622a84e
commit
580e1ad3d3
106
src/java/com/test/servlets/CreaPompierServlet.java
Normal file
106
src/java/com/test/servlets/CreaPompierServlet.java
Normal file
@ -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 <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 CreaPompierServlet</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Servlet CreaPompierServlet 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/CreaPompier.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 {
|
||||
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<Integer> lesNouveauxPompiers = (ArrayList<Integer>) 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";
|
||||
}// </editor-fold>
|
||||
|
||||
}
|
87
src/java/com/test/servlets/ModifPompierServlet.java
Normal file
87
src/java/com/test/servlets/ModifPompierServlet.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 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 <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 ModifPompierServlet</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Servlet ModifPompierServlet 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>
|
||||
|
||||
}
|
@ -54,6 +54,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<br />
|
||||
<input type="button" name="btNouvP" value="Créer nouveau pompier"/>
|
||||
<a href="ModifPompier"><input type="button" name="btModifP" value="Modifier la fiche pompier"/></a>
|
||||
<a href="CreaPompier" ><input type="button" name="btNouvP" value="Créer nouveau pompier"/></a>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -12,6 +12,14 @@
|
||||
<servlet-name>authentifServlet</servlet-name>
|
||||
<servlet-class>com.test.servlets.authentifServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>ModifPompierServlet</servlet-name>
|
||||
<servlet-class>com.test.servlets.ModifPompierServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>CreaPompierServlet</servlet-name>
|
||||
<servlet-class>com.test.servlets.CreaPompierServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>PompierServlet</servlet-name>
|
||||
<url-pattern>/Pompier</url-pattern>
|
||||
@ -24,6 +32,14 @@
|
||||
<servlet-name>authentifServlet</servlet-name>
|
||||
<url-pattern>/Authentification</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>ModifPompierServlet</servlet-name>
|
||||
<url-pattern>/ModifPompier</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>CreaPompierServlet</servlet-name>
|
||||
<url-pattern>/CreaPompier</url-pattern>
|
||||
</servlet-mapping>
|
||||
<session-config>
|
||||
<session-timeout>
|
||||
30
|
||||
|
Loading…
x
Reference in New Issue
Block a user