Advertisement
ADL_Rodrigo_Silva

Untitled

Feb 28th, 2022
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package cl.adl.ejemplo;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5.  
  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.Cookie;
  9. import javax.servlet.http.HttpServlet;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12.  
  13. /**
  14.  * Servlet implementation class RecuperaCookie
  15.  */
  16. @WebServlet("/RecuperaCookie")
  17. public class RecuperaCookie extends HttpServlet {
  18.  
  19.         protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
  20.         Cookie[] cookies = request.getCookies();
  21.         PrintWriter print = response.getWriter();
  22.        
  23.         print.println("<html><body>");
  24.         print.println("<h2><i>Cookie recuperada correctamente:</i></h2><br>");
  25.        
  26.         for(int i = 0; i < cookies.length; i++) {
  27.             print.println("Id de la cookie: <strong>"+ cookies[i].getValue() + "</strong>");
  28.             print.println("<br>");
  29.             print.println("Valor de la cookie: <strong>" + cookies[i].getName()+"</strong>");
  30.             print.println("<br>");
  31.         }
  32.        
  33.         print.println("</body></html>");
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement