Cookie一坑


LocalDateTime localDateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒");
String time = localDateTime.format(formatter);

学习Cookie时,通过

Cookie cookie = new Cookie("time", time);

resp.addCookie(cookie);

添加以上的时间信息,可是服务器一直报错500,因为Cookie信息中不能有空格,更改格式化信息即可。

或者
String time_enc = URLEncoder.encode(time, "utf8");
然后用time_enc作为参数,但是输出到页面中也要调用相应的解码函数
URLDecoder.decode(cookie.getValue(), "utf8")
原文地址:https://www.cnblogs.com/-rzx-/p/12577112.html