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(); } }
原文:http://www.cnblogs.com/feifeishi/p/6063063.html