มันมีไฟล์ JSP สองไฟล์คือ login.jsp และ index.jsp
รหัสมีดังนี้:
เข้าสู่ระบบ.jsp
<%@ page language = "java" contentType = "ข้อความ/html; charset = utf-8" pageencoding = "utf-8"%> <! doctype html สาธารณะ "-// w3c // dtd html 4.01 transitional // en" "http://www.w3.org/tr/html4/loose.dtd"><html> <head> <meta http-equiv =" content-ype "content =" text/html; charset = utf-8 "> <title> method = "post"> ชื่อผู้ใช้: <input type = "text" name = "name"/> <อินพุต type = "subment" value = "ส่ง"/> </form> </body> </html>
index.jsp
<%@ page language = "java" contentType = "ข้อความ/html; charset = utf-8" pageencoding = "utf-8"%> <! doctype html สาธารณะ "-// w3c // dtd html 4.01 transitional // en" "http://www.w3.org/tr/html4/loose.dtd"><html> <head> <meta http-equiv =" content-ype "content =" text/html; charset = utf-8 "> <title> null &&! name.trim (). เท่ากับ ("")) {คุกกี้คุกกี้ = คุกกี้ใหม่ ("ชื่อ", ชื่อ); cookie.setMaxage (30); // ตั้งค่าระยะเวลาความถูกต้องของคุกกี้เป็น 30sresponse.addcookie (คุกกี้);} else {คุกกี้ [] คุกกี้ = request.getCookies (); ถ้า (คุกกี้! = null && cookies.length> 0) {สำหรับ (คุกกี้คุกกี้: คุกกี้) cookie.getValue (); name = val;}}}} ถ้า (ชื่อ! = null &&! name.trim (). เท่ากับ ("")) {out.print ("สวัสดี:" + ชื่อ);ข้างต้นคือ Javaweb โดยใช้คุกกี้เพื่อจำลองฟังก์ชั่นการเข้าสู่ระบบอัตโนมัติ ฉันหวังว่ามันจะเป็นประโยชน์กับทุกคน หากคุณมีคำถามใด ๆ โปรดฝากข้อความถึงฉันและบรรณาธิการจะตอบกลับทุกคนในเวลา ขอบคุณมากสำหรับการสนับสนุนเว็บไซต์ Wulin.com!