2つのJSPファイル、つまりlogin.jspとindex.jspが含まれています
コードは次のとおりです。
login.jsp
<%@ page Language = "Java" contentType = "text/html; charset = utf-8" pageencoding = "utf-8"%> < "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv =" content-type "content =" text/html; charset = utf-8 "> <tittle> login interface </title> <body> <body> <body> <body> <body> <body> <body> <body> method = "post"> username:<入力タイプ= "text" name = "name"/> <入力タイプ= "" value = "submit"/> </form> </body> </html>
index.jsp
<%@ page Language = "Java" contentType = "text/html; charset = utf-8" pageencoding = "utf-8"%> < "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv =" content-type "content =" text/html; charset = utf-8 "> <title> welcome </title> <body> <body> <body> <string> <%string> <body> <body> <body> <body> <body> <%sinte &&!name.trim()。equals( "")){cookie cookie = new cookie( "name"、name); cookie.setmaxage(30); // Cookieの有効期間を30Sresponse.AddCookie(cookie);} else {cookie [] cookie = request.getCookies(); if(cookies!= null && cookies.length> 0){for(cookie cookies:cookie){string cookiename = cookie.getName(); cookie.getValue(); name = val;}}}} if(name!= null &&!name.trim()。equals( "")){out.print( "hello:" + name);} else {// login interface response.sendredirect.sendredirect( "login.jsp");}%> <>上記は、Cookieを使用して自動ログイン機能をシミュレートするJavawebです。私はそれが誰にでも役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は、すべての人に時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます!