struts中Cookie实现记住密码
HttpServletRequest request = ServletActionContext.getRequest(); Cookie[] cookies = request.getCookies(); if(number.equals("")==false) { //创建Cookie Cookie cookie = new Cookie("Number", number); //设置Cookie的生命周期 cookie.setMaxAge(60*60*24*365); ServletActionContext.getResponse().addCookie(cookie); } else if(cookies!=null){ for(int i=0; i<cookies.length; i++) { if(cookies[i].getName().equals("Number")) number=cookies[i].getValue().toString(); } } if(password.equals("")==false) { //创建Cookie Cookie cookie = new Cookie("Password", password); //设置Cookie的生命周期 cookie.setMaxAge(60*60*24*365); ServletActionContext.getResponse().addCookie(cookie); } else if(cookies!=null){ for(int i=0; i<cookies.length; i++) { if(cookies[i].getName().equals("Password")) password=cookies[i].getValue().toString(); } }