Contiene dos archivos JSP, a saber, login.jsp y index.jsp
El código es el siguiente:
Login.jsp
<%@ page lenguaje = "java" contentType = "text/html; charset = utf-8" pageEncoding = "utf-8"%> <! DocType html público "-// w3c // dtd html 4.01 transición // en" " "http://www.w3.org/tr/html4/loose.dtd"><html><head><meta http-equiv =" content-type "content =" text/html; charset = utf-8 "> <title> interfaz de inicio </titter> </thead> <form) Method = "Post"> UserName: <input type = "text" name = "name"/> <input type = "subt" value = "subt"/> </form> </body> </html>
index.jsp
<%@ page lenguaje = "java" contentType = "text/html; charset = utf-8" pageEncoding = "utf-8"%> <! DocType html público "-// w3c // dtd html 4.01 transición // en" " "http://www.w3.org/tr/html4/loose.dtd"><html><head><meta http-equiv =" content-type "content =" text/html; charset = utf-8 "> <title> Bienvenido </title> </head> <sode> <%string name" name "; &&! name.trim (). Equals ("")) {Cookie Cookie = new Cookie ("Nombre", Nombre); Cookie.SetMaxage (30); // Establezca el período de validez de cookie en 30sResponse.addcookie (cookie);} else {cookie [] cookies = request.getcookies (); if (cookies! = Null && cookies.length> 0) {for (cookie cookie: cookies) {string cookiename = cookie.getName (); if ("name" .equals (cookiename) cookie.getValue (); name = val;}}}} if (name! = null &&! name.trim (). iguales ("")) {out.print ("hello:" + name);} else {// redirige a la interfaz de inicio de sesión.sendredirect ("login.jsp");}%> </body> </html>Lo anterior es el Javaweb que usa cookies para simular la función de inicio de sesión automática. Espero que sea útil para todos. Si tiene alguna pregunta, déjame un mensaje y el editor responderá a todos a tiempo. ¡Muchas gracias por su apoyo al sitio web de Wulin.com!