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 = {
"/ServletModificacionCookies",
"/modificacion-de-cookies"
}
)
public class ServletModificacionCookies extends HttpServlet {
private String generarDocumentoHtml(HttpServletRequest request) {
StringBuffer documentoHtml = new StringBuffer();
documentoHtml.append("");
documentoHtml.append("");
documentoHtml.append("
");
documentoHtml.append("");
documentoHtml.append("
");
documentoHtml.append("
ServletModificacionCookies
");
documentoHtml.append("");
documentoHtml.append("");
documentoHtml.append("
");
documentoHtml.append("
¿Cookies modificadas o creadas (y entregadas)?
");
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(request));
}
}