Ini berisi dua file JSP, yaitu login.jsp dan index.jsp
Kodenya adalah sebagai berikut:
Login.jsp
<%@ page language = "java" contentType = "text/html; charset = utf-8" pageEncoding = "utf-8"%> <! Doctype html public "-// w3c // dtd html 4.01 transisi // en" "http://www.w3.org/tr/html4/loose.dtd"><html><head><meta http-equiv =" content-type "content =" text/html; charset = uTf-8 "> <itement> interface login </title> </head; Method = "POST"> Nama pengguna: <input type = "text" name = "name"/> <input type = "kirim" value = "kirim"/> </form> </body> </html>
index.jsp
<%@ page language = "java" contentType = "text/html; charset = utf-8" pageEncoding = "utf-8"%> <! Doctype html public "-// w3c // dtd html 4.01 transisi // en" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Welcome</title></head><body><%String name = request.getParameter("name");if(name != null &&! Name.trim (). Equals ("")) {cookie cookie = cookie baru ("name", name); cookie.setmaxage (30); // Atur periode validitas cookie ke 30sresponse.addcookie (cookie);} else {cookie [] cookies = request.getCookies (); if (cookies! = Null && cookies.length> 0) {for (cookie cookie "cookies) {string cookeIsame = cookie.getName (); cookie.getValue (); name = val;}}}} if (name! = null &&! name.trim (). equals ("")) {out.print ("halo:" + name);} else {// jika tidak mengarahkan ulang ke login response.sendReDirect ("lOGSPS");Di atas adalah Javaweb menggunakan cookie untuk mensimulasikan fungsi login otomatis. Saya harap ini akan membantu semua orang. Jika Anda memiliki pertanyaan, silakan tinggalkan saya pesan dan editor akan membalas semua orang tepat waktu. Terima kasih banyak atas dukungan Anda ke situs web Wulin.com!