ฟังก์ชั่นของการจดจำรหัสผ่านบัญชีเป็นสิ่งจำเป็นในการออกแบบที่สำเร็จการศึกษา
ก่อนอื่นหน้าเข้าสู่ระบบ
login.jsp รหัส:
<%@page import = "org.apache.commons.lang.stringutils"%> <%@page language = "java" contentType = "text/html; charset = utf-8" pageencoding = "UTF-8" /JavaScript " src = "$ {pageContex ความสูง: 100%; ขอบด้านบน: -225px; รหัสผ่าน = ""; i = 0; i <cookies.length; i ++) {ถ้า (คุกกี้ [i] .getName (). เท่ากับ ("cookie_user")) {ค่าสตริง = คุกกี้ [i] .getValue (); องค์ประกอบ [0])) {ชื่อ = องค์ประกอบ [0]; องค์ประกอบ [1];}}}}}}}}}}}}}}} catch (ข้อยกเว้น e) {} %> <div style = ""> <div> <div> <! Oft yahei '; "> <p style =" ตำแหน่ง: ญาติ; margin-top: 200px; padding-left: 20px; "> <span Style = "Font-Size: 30px; Font-Weight: 800;"> ระบบการจัดการการบำรุงรักษาอัตโนมัติ </span> <br/> <pan> ระบบการจัดการการบำรุงรักษายานพาหนะ </span> </p> </div> </div> econtext.request.contextpath}/img/split.png "style =" ตำแหน่ง: Absolute; ซ้าย: 0px; top: 30px; "/>> </div> <div region = "center"> <div iconcls = "icon-user" style = "text-allign: center; width: 300px; ความสูง: 260px; padding-top: 50px;"> <form id = "ff" method = "โพสต์"> <div> = "< %= ชื่อ %>"> <a id = "dd" href = "#"> </a> </div> <div style = "margin-top: 20px;"> <อินพุต id = "รหัสผ่าน" name = "passwords" type = "password" data-options = "iconcls: 'ไอคอนล็อค', พรอมต์: 'โปรดป้อนรหัสผ่านของคุณ'" value = "< %= รหัสผ่าน %>" flag "name =" flag "type =" ช่องทำเครื่องหมาย "value =" 1 "checked =" ตรวจสอบ "/> จดจำบัญชี </span> </div> <div style = "Clear: ทั้งสอง;"> </div> <div style = "margin-top: 20px;"> <p> <a href = "#" id = "submentbtn" iconcls = "icon-accept"> login </a> <a style = "margin-left: 30px; /a> </p> </div> </form> </div> </div> <div Region = "East"> </div> <div Region = "South" style = "ความสูง: 0px;"> </div> </div> </div> </div> <!-ส่วนเนื้อหาหลักสิ้นสุดลง-> </div> </div> </div> </div> <script type = "text/javascript"> $ (ฟังก์ชั่น () {console.log (" h/] "); // ส่งแบบฟอร์ม $ ("#submingbtn ") คลิก (ฟังก์ชัน () {// พิจารณาว่าว่างเปล่าถ้า ($ ("#บัญชี "). val () ==" ") { $ messager.alert ('ข้อความล็อกอิน', 'บัญชีของผู้ใช้ไม่สามารถว่างเปล่า', 'ข้อมูล'); {url: "$ {pageContext.request.contextpath} /users/login.html", ความสำเร็จ: ฟังก์ชั่น (ข้อมูล) {data = json.parse (ข้อมูล); $ messager.alert ('ข้อความเข้าสู่ระบบ', data.errormsg, 'info'); NULL && HISURL.Length> 0) {window.location.href = "$ {pageContext.request.contextpath}"+hiSurl; window.location.href = "$ {pageContext.request.contextpath} /index/main.html"; });ส่วนหนึ่งของรหัส Java ที่ประมวลผลในพื้นหลัง:
com.javaweb.controller; LF4J.LoggerFactory; org.springframework.contex G.SpringFramework.web.bind.annotation.responsebody; นำเข้า com.javaweb.service.impl.servicefactory; oller {ส่วนตัว logger สุดท้ายคงที่ logger = loggerFactory.getLogger (userInFocontroller.class); @AutoWired ServiceFactory ServiceFactory;/*** เข้าสู่ระบบ* @param Request Request* @param รุ่นโมเดล* @param ข้อมูลบัญชีบัญชี* @return*/@requestmapping ("/ล็อกอิน") @ResponseBody สตริงสาธารณะ ing (บัญชี)); RespontyFail ("พารามิเตอร์ที่ส่งมานั้นว่างเปล่า!")}} {ถ้า stringutils.isblank (account.getActAncountNumber ()) {returbe responsefail ("บัญชีของผู้ใช้ว่างเปล่า"); ory.getUservalidateservice (). ผู้ใช้งาน (บัญชี); ResponseFail ("ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง"); คุกกี้ ("cookie_user", loginebean.getAccountNumber ()+"-"+loginebean.getPasswords ()); COOKIE.SetMaxage (60*60*24*3); // บันทึกการตอบสนอง Addcookie (คุกกี้); ountnumber ()); logger.info ("การจัดเก็บคุกกี้ของผู้ใช้:"+loginebean.getAccountNumber ()); โมเดลโมเดลพารามิเตอร์* @param หมายเลขบัญชี* @return*/@requestmapping ("/{accountnum} /logout.html") สตริงสาธารณะ Logout (HttpservletRequest Request, Model Model,@PathVariable ("AccountNum") String บัญชี) {logger.info ("ผู้ใช้"+accountnum+", ออกจากระบบ ... ");เอฟเฟกต์การทำงาน:
หลังจากป้อนรหัสผ่านบัญชีของคุณเข้าสู่ระบบ:
เข้าสู่ระบบอีกครั้งหลังจากเข้าสู่ระบบ:
ข้างต้นคือการแนะนำของบรรณาธิการให้คุณใช้คุกกี้ใน Java Web เพื่อจดจำบัญชีและรหัสผ่านของผู้ใช้ ขอบคุณมากสำหรับการสนับสนุนเว็บไซต์ Wulin.com!