여기에는 2 개의 JSP 파일, 즉 login.jsp 및 index.jsp가 포함되어 있습니다
코드는 다음과 같습니다.
login.jsp
<%@ page language = "java"contmenttype = "text/html; charset = utf-8"pageencoding = "utf-8"%> <! doctype html public "-// w3c // dtml 4.01 Transitional // en" "http://www.w3.org/tr/tr/html4/loose.dtd"> html> html> http-quiv ="content-type "content ="text/html; charset = utf-8 "> <title> </head> <index.jsp" 메소드 = "post"> username : <input type = "text"name = "name"/> <input type = "제출"value = "제출"/> </form> </body> </html>
index.jsp
<%@ page language = "java"contmenttype = "text/html; charset = utf-8"pageencoding = "utf-8"%> <! doctype html public "-// w3c // dtml 4.01 Transitional // en" "http://www.w3.org/tr/tr/html4/loose.dtd"> html> html> http-tequiv ="content-type "content ="text/html; charset = utf-8 "> </title> </head> <%string = name"); &&! name.trim (). equals ( "")) {쿠키 쿠키 = 새 쿠키 ( "이름", 이름); cookie.setmaxage (30); // 쿠키 유효성 기간을 30SResponse.addCookie (쿠키);} else {쿠키 [] 쿠키 = request.getCookies (); if (cookies! = null && cookies.length> 0) {for (cookie cookie : cookies) {string cookiename = cookie.getname (if (for Quicals)); cookie.getValue (); name = val;}}}} if (name! = null &&! name.trim (). equals ( "")) {out.print ( "hello :" + name);} else {// login interface resonge.SendRedirect ( "login.jsp")로 리디렉션됩니다.위는 쿠키를 사용하여 자동 로그인 기능을 시뮬레이션하는 javaweb입니다. 모든 사람에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 모든 사람에게 답장을 드리겠습니다. Wulin.com 웹 사이트를 지원해 주셔서 대단히 감사합니다!