当前位置:网站首页>Servlet uses cookies to realize the last login time of users

Servlet uses cookies to realize the last login time of users

2022-07-27 16:53:00 TDSSS

problem : Exception encountered

An invalid character [32] was present in the Cookie value

reason :

A space appears when formatting the time ,cookie Spaces are not allowed in the value of

//  Get the current time 
long currentTimeMillis = System.currentTimeMillis();
String pattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, Locale.getDefault());
String time = simpleDateFormat.format(currentTimeMillis);

terms of settlement :

Send... To the client cookie Time to time utf-8 code , Decode it when you use it

//  hold time Encoding 
time = URLEncoder.encode(time, "utf-8");
// Take from cookie Get the time to decode 
value = URLDecoder.decode(value, "utf-8");

原网站

版权声明
本文为[TDSSS]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/208/202207271450365616.html