后台: 登陆成功之后将用户名密码放入到cookie中 // 放到cookie中 String flag = request.getParameter("flag"); if(flag!=null && flag.equals("1")){ Cookie cookieUser = new Cookie("cookie_user", userId+"-"+userPwd); cookieUser.setMaxAge(60*60*24*30*120); response.addCookie(cookieUser); }else{ Cookie cookie = new Cookie("cookie_user",null); cookie.setMaxAge(0); response.addCookie(cookie); } 前台:(注意需要引入jquery.cookie.js) <div class="mui-input-row"> <label>账号</label> <input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入账号"> </div> <div class="mui-input-row"> <label>密码</label> <input id='password' type="password" class="mui-input-clear mui-input-password" placeholder="请输入密码"> </div> <li class="mui-table-view-cell"> 记住用户名和密码 <input id="flag" type="hidden" name="flag" value="1"/> </li> //读取Cookie值 var cookiesUser = $.cookie("cookie_user"); if (cookiesUser != undefined) { $("#account").val(cookiesUser.split('-')[0]); $("#password").val(cookiesUser.split('-')[1]); }
百度云盘链接:https://pan.baidu.com/s/1QnKQOq3xW6OlrGYLdVkgqQ 密码:j3yv