解决方案
修改tomcat配置文件${tomcat_home}\conf\context.xml
<?xml version="1.0" encoding="UTF-8”?>
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!-- <Manager pathname="" /> -->
<!-- 添加代码 -->
<CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor"/>
</Context>
重启tomcat
原因
在8.5之前在tomcat源码中addCookie方法中的generateHeader的实现为LegacyCookieProcessor,在tomcat8.5版本默认使用的是rfc6265实现的,
rfc6265实现规则为:
- 必须是1-9、a-z、A-Z、. 、- (注意是-不是_)这几个字符组成
- 必须是数字或字母开头 (所以以前的cookie的设置为.XX.com 的机制要改为 XX.com 即可)
- 必须是数字或字母结尾
所以将这个实现改为8.0的实现类就不会报错了。