¿Cómo mostrar contenido html en java?
Espero adoptar!
doGet vacío protegido (solicitud HttpServletRequest, respuesta HttpServletResponse) lanza ServletException, IOException {
// TODO Código auxiliar de método generado automáticamente
String cookieName = "userName"
String cookiePwd = "pwd";
Cookie[] cookies = request.getCookies(
String userName = "";
String pwd = "";
boolean isChecked = false
// Si la matriz de cookies no es nula, significa que se ha configurado antes, es decir, se ha configurado ha iniciado sesión antes,
if (cookies ! = null)
{
for (int i=0; ilt; cookies.length; i)
p>{
Cookie cookie = cookies[i];
if (cookieName.getName()))
{ p>
nombre de usuario = cookie.getValue();
}
if (cookiePwd.equals(cookie.getName()))
{
pwd = cookie.getValue();
}
if ("Check".equals(cookie.if ("Check".equals(cookie.getName) ()) )
{
isChecked = cookie.getValue().equals("sí") verdadero: falso
}
}
}
respuesta.setContentType("text/html;charset=GBK");
request.setCharacterEncoding("gbk");
PrintWriter out = respuesta.getWriter();
String docType = "lt;DOCTYPE HTML PUBLIC\"-//W3C/DTD HTML 4.0 Transitional//EN\" gt; ";
String title = "ServletLoginDemo";
out.println(docType "lt;htmlgt;" "lt;headgt;"
"lt; meta http- equiv=\"Tipo de contenido\" contenido=\"texto
/html; charset=gbk\"gt;"
"lt; estilo tipo=\"text/css\"gt;"
".textsize {ancho: 150px; fondo :#B1DC87}"
"lt;/stylegt;"
"lt;titlegt;" título
"lt;/titlegt lt;/headgt; ; " "lt; cuerpo bgcolor=\"#FDF5E6\"gt;"
"lt; br /gt;"
"br /gt;"
"lt;centergt;" "lt;h1gt;Cookie Login Demolt;/h1gt;"
"lt.hr /gt;"
"lt;acción de formulario =\"CookieTest\" método=\"post\"gt;"
(userName == null ?"UserName:lt; input class=\"textsize\" type=\"text\" nombre =\"Nombre de usuario\" ancho="20\"gt;lt;/inputgt;lt;br /gt;" : "Nombre de usuario:lt;input class=\"textsize\" tipo=\"text\" nombre=\ "Nombre de usuario\" ancho=\"20\" valor=" nombre de usuario "gt;/inputgt;lt;br /gt;")
(pwd == null ?"Secret?Code:lt;input class=\"tamaño de texto\" tipo=\"contraseña\" nombre=\"Contraseña\"gt;/inputgt;lt;br /gt;" : "¿Contraseña? Código: lt;input clase=\"tamaño de texto\" tipo =\"contraseña\" nombre=\"Contraseña\" valor=" pwd "gt;/inputgt;lt;br /gt;")
(isChecked ?"lt;input type=\"checkbox \" name=\"Check\" check=\"true\"gt; Recordar contraseña lt;/inputgt;": "lt; input type=\"checkbox\" name=\"Check\"gt; Recordar contraseña lt ;/inputgt;")
"lt;centergt; lt;tipo de entrada=\"enviar\" valor=\"login\"gt;lt;/centergt;"
"lt;/formgt;"
"lt;/centergt; lt;/bodygt; lt;/htmlgt;");
}