踩坑的Tomcat9.0.37([http-nio-8080-exec-20] 2016 Aug 20 12:04:49 WARN WARN:187 - Handler executi)

出现的现象

[http-nio-8080-exec-20] 2016 Aug 20 12:04:49 WARN WARN:187 - Handler execution resulted in exception
java.lang.IllegalArgumentException: An invalid domain [.itcast.cn] was specified for this cookie at org.apache.tomcat.util.http.Rfc6265CookieProcessor.validateDomain
(Rfc6265CookieProcessor.java:1
at org.apache.tomcat.util.http.Rfc6265CookieProcessor.generateHeader)
(Rfc6265CookieProcessor.java:12
at org.apache.catalina.connector.Response.generateCookieString(Response.java:989)
at org.apache.catalina.connector.Response.addCookie(Response.java:937)
at org.apache.catalina.connector.ResponseFacade.addCookie(ResponseFacade.java:386)

原因分析

tomcat升级到8.5版本以上,
发现登录和退出报错,logs报错为下:
[http-nio-8080-exec-20] 2016 Aug 20 12:04:49 WARN WARN:187 - Handler execution resulted in exception
java.lang.IllegalArgumentException: An invalid domain [.itcast.cn] was specified for this cookie at org.apache.tomcat.util.http.Rfc6265CookieProcessor.validateDomain
(Rfc6265CookieProcessor.java:1
at org.apache.tomcat.util.http.Rfc6265CookieProcessor.generateHeader)
(Rfc6265CookieProcessor.java:12
at org.apache.catalina.connector.Response.generateCookieString(Response.java:989)
at org.apache.catalina.connector.Response.addCookie(Response.java:937)
at org.apache.catalina.connector.ResponseFacade.addCookie(ResponseFacade.java:386)

具体因素

domain规则的改变
(8.5版本以下)
void setDomain(String pattern)和void setDomain()方法
上面两个是针对cookie的Domain属性的,是用来指定浏览器的访问域。例如某域名为"itcast.cn",那么,当设置Domain属性是,其值必以“.”。开头例如:Domain=.itcast.cn。默认情况下Domain值为当前主机名,浏览器在访问当前主机资源时,会将Cookie信息送给服务器。
(8.5版本以上)
1、必须是由1-9、a-z、A-Z、. 、- (注意是-不是_)这几个字符组成
2、必须是由数字或字母开头 (所以以前的cookie的设置为.itcast.cn 的机制要改为itcast.cn 即可)
3、必须以数字或字母结尾

解决方法

升级处理cookie的domain的地方即可 由 (.itcast.cn 的机制要改为itcast.cn )

你可能感兴趣的:(笔记,tomcat,java,cookie,http)