怎樣更改瀏覽器的cookie保存時間
怎樣更改瀏覽器的cookie保存時間
慕碼人8056858
2019-05-16 10:10:35
TA貢獻1796條經驗 獲得超4個贊
int maxAge = 365*24*3600;//cookie的存活期
CookieUtils.addCookie("name",value,response,maxAge,request.getContextPath());
public static void addCookie(String name, String value, HttpServletResponse response, int maxAge, String path) throws Exception {
String str = URLEncoder.encode(value, "UTF-8");
Cookie cookie = new Cookie(name, str);
cookie.setPath(path);
cookie.setMaxAge(maxAge);
response.addCookie(cookie);
}
舉報