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 = { "/ServletLecturaCookies", "/lectura-de-cookies" } ) public class ServletLecturaCookies extends HttpServlet { private String tablaHtmlCookies(HttpServletRequest request) { StringBuffer tablaHtml = new StringBuffer(); Cookie[] galletitas = request.getCookies(); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); if (galletitas != null) { for (Cookie cookie : galletitas) { tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); tablaHtml.append(""); } } tablaHtml.append(""); tablaHtml.append("
Tabla de Cookies
getName()getValue()getMaxAge()getDomain()getPath()getSecure()
" + cookie.getName() + "" + cookie.getValue() + "" + cookie.getMaxAge() + "" + cookie.getDomain() + "" + cookie.getPath() + "" + cookie.getSecure() + "
"); return tablaHtml.toString(); } private String generarDocumentoHtml(HttpServletRequest request) { StringBuffer documentoHtml = new StringBuffer(); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append("ServletLecturaCookies"); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append(""); documentoHtml.append("
"); documentoHtml.append("
"); documentoHtml.append("

ServletLecturaCookies

"); documentoHtml.append("
"); documentoHtml.append("
"); documentoHtml.append(""); documentoHtml.append("
"); documentoHtml.append("
"); documentoHtml.append(this.tablaHtmlCookies(request)); documentoHtml.append("
"); documentoHtml.append("
"); documentoHtml.append(""); documentoHtml.append(""); return documentoHtml.toString(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); PrintWriter salida = response.getWriter(); salida.print(this.generarDocumentoHtml(request)); } }