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

这句话的意思是
一个不识别的字符[32]出现在了cookie当中
由于tomcat的版本比较高,所以在addCookie时是不能使用空格的 而在ASCII码中32对应的就是空格。只要把后台代码中的空格删掉就可以了。
我的代码:是在cookie中添加了时间,而时间的格式化中我是用了format。上代码:

Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String currentTime = format.format(date);
Cookie cookie = new Cookie("accessTime",currentTime);
cookie.setMaxAge(60*60*10);
response.addCookie(cookie);

这里的天和小时之间用的是空格分隔,所以会报错。

只要将这个空格修改掉就可以了。比如改成 - 



原文链接:https://blog.csdn.net/caopengflying/article/details/78965733