Advertisement
ADL_Rodrigo_Silva

Untitled

Feb 28th, 2022
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 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 ManejoCookies
  15.  */
  16. @WebServlet("/ManejoCookies")
  17. public class ManejoCookies extends HttpServlet {
  18.  
  19.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
  20.        
  21.         Cookie cookie = new Cookie("userX","miercoles22febrero2022");
  22.        
  23.         cookie.setMaxAge(9000);
  24.         cookie.setComment("Cookie guardada con propositos educativos");
  25.        
  26.         response.addCookie(cookie);
  27.    
  28.         PrintWriter print = response.getWriter();
  29.         print.println("<html><body>");
  30.         print.println("<h2><i>Cookie guardada correctamente:</i></h2><br>");
  31.  
  32.         print.println("Valor de la cookie: <strong>"+ cookie.getValue() + "</strong>");
  33.         print.println("<br>");
  34.         print.println("Tiempo de la duración de la cookie: <strong>" + cookie.getMaxAge()+"</strong>");
  35.         print.println("<br>");
  36.         print.println("Comentario: <strong>" + cookie.getComment() + "</strong>");
  37.         print.println("</body></html>");
  38.    
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement