package io.bitbucket.NombreDeUsuario.jee03.servlets; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet( urlPatterns = { "/ServletCreacionEntregaCookie", "/creacion-y-entrega-de-cookies" } ) public class ServletCreacionEntregaCookies extends HttpServlet { private String generarDocumentoHtml() { StringBuffer documentoHtml = new StringBuffer(); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append("ServletCreacionEntregaCookies"); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append("
"); documentoHtml.append("
"); documentoHtml.append("

ServletCreacionEntregaCookies

"); documentoHtml.append("
"); documentoHtml.append("
"); documentoHtml.append(""); documentoHtml.append("
"); documentoHtml.append("
"); documentoHtml.append("

¿Cookies creadas (y entregadas) o modificadas?

"); documentoHtml.append("
"); documentoHtml.append("
"); documentoHtml.append(""); documentoHtml.append(""); return documentoHtml.toString(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Cookie galletita1 = new Cookie("a", String.valueOf(Math.random())); Cookie galletita2 = new Cookie("b", String.valueOf(Math.random())); Cookie galletita3 = new Cookie("c", String.valueOf(Math.random())); response.addCookie(galletita1); response.addCookie(galletita2); response.addCookie(galletita3); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); PrintWriter salida = response.getWriter(); salida.print(this.generarDocumentoHtml()); } }