javaWeb remember user account password

Eight, the realization of the function of remembering the account password

8.1 The user
<a href="/netBookStore/CheckUserLogin.do"></a>accesses , and calls the doGet() method.

8.2 The user logs in for the first time: the client does not have the corresponding cookie, and directly forwards it to the login.jsp page to log in

Cookie[] cookies=request.getCookies();
        if(cookies==null){
response.sendRedirect("/netBookStore/user/login.jsp");
}

8.3 The user logs in through the login.jsp page, visits the CheckUserLogin.java Servlet controller again, and calls the doPost() method.

8.4 If the user chooses to remember the account and password, the user's account and password information will be stored in the cookie, and the selection result of whether to remember the account and password will be stored together.

if((request.getParameter("check")!=null)&&
                    request.getParameter("check").equals("check")){
                Cookie nameCookie=new Cookie("userName",userName);
                Cookie checkCookie=new Cookie("isChecked","1");
                response.addCookie(nameCookie);
                response.addCookie(checkCookie);
            }else{
                Cookie nameCookie=new Cookie("userName","");
                Cookie checkCookie=new Cookie("isChecked","0");
                response.addCookie(nameCookie);
                response.addCookie(checkCookie);}

8.5 When the user tries to log in again, the cookie information stored in the client is read, stored in the session object, and displayed on the login.jsp page

<input type="text" name="userName" id="userName" value="${user.userName }">
<input type="checkbox" name="check" id="check" value="check" ${sessionScope.isChecked }>

Note: As long as the checked attribute appears, the selection box will be selected, and only when the checked attribute does not appear will it be unselected

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325579066&siteId=291194637