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 = {
"/ServletEliminacionCookies",
"/borrado-de-cookies"
}
)
public class ServletBorradoCookies extends HttpServlet {
private String generarDocumentoHtml(HttpServletRequest request) {
StringBuffer documentoHtml = new StringBuffer();
documentoHtml.append("");
documentoHtml.append("");
documentoHtml.append("
");
documentoHtml.append("");
documentoHtml.append("
");
documentoHtml.append("
ServletBorradoCookies
");
documentoHtml.append("");
documentoHtml.append("");
documentoHtml.append("
");
documentoHtml.append("
¿Cookies borradas?
");
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", "");
galletita1.setMaxAge(0);
Cookie galletita2 = new Cookie("b", "");
galletita2.setMaxAge(0);
Cookie galletita3 = new Cookie("c", "");
galletita3.setMaxAge(0);
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));
}
}