java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie解决方法
当项目中使用单点登录功能时,通常会使用cookie进行信息的保存,这样就可以在多个子域名上存取用户信息。
比如有三个domain分别为test.com,cml.test.com,b.test.com这三个域名下的cookie是需要互相访问的。这时会在response上写入cookie信息
Cookie cookie = new Cookie("testCookie", "test");
cookie.setDomain(".test.com");
cookie.setPath("/");
cookie.setMaxAge(36000);
resp.addCookie(cookie);
这样写在tomcat8.0上是没问题的,三个域名可以共享cookie信息。但是把它放到tomcat8.5上就报错了
java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie
at org.apache.tomcat.util.http.Rfc6265CookieProcessor.validateDomain(Rfc6265CookieProcessor.java:181)
at org.apache.tomcat.util.http.Rfc6265CookieProcessor.generateHeader(Rfc6265CookieProcessor.java:123)
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)
at com.cml.mvc.controller.HelloWorld.str(HelloWorld.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
在tomcat8.5上是使用org.apache.tomcat.util.http.Rfc6265CookieProcessor
The standard implementation of CookieProcessor is org.apache.tomcat.util.http.Rfc6265CookieProcessor.
This cookie processor is based on RFC6265 with the following changes to support better interoperability:
Values 0x80 to 0xFF are permitted in cookie-octet to support the use of UTF-8 in cookie values as used by HTML 5.
For cookies without a value, the '=' is not required after the name as some browsers do not sent it.
The RFC 6265 cookie processor is generally more lenient than the legacy cookie parser. In particular:
The '=' and '/' characters are always permitted in a cookie value.
Name only cookies are always permitted.
The cookie header is always preserved.
No additional attributes are supported by the RFC 6265 Cookie Processor.
在tomcat8.0上使用的是org.apache.tomcat.util.http.LegacyCookieProcessor
The standard implementation of CookieProcessor is org.apache.tomcat.util.http.LegacyCookieProcessor. Note that it is anticipated that this will change to org.apache.tomcat.util.http.Rfc6265CookieProcessor in a future Tomcat 8 release.
This is the legacy cookie parser based on RFC6265, RFC2109 and RFC2616. It implements a strict interpretation of the cookie specifications. Due to various interoperability issues with browsers not all strict behaviours are enabled by default and additional options are available to further relax the behaviour of this cookie processor if required.
问题就可以定位在CookieProcessor不同实现引起的。
原因分析见下半篇博客:An invalid domain [.test.com] was specified for this cookie 原因分析
解决方法:
指定完整的domain信息,但是这样单点登录就会有问题了
Cookie cookie = new Cookie("testCookie", "test");
cookie.setDomain("cml.test.com");
cookie.setPath("/");
cookie.setMaxAge(36000);
resp.addCookie(cookie);
2.设置为一级域名(推荐)
Cookie cookie = new Cookie("testCookie", "test");
cookie.setDomain("test.com");
cookie.setPath("/");
cookie.setMaxAge(36000);
resp.addCookie(cookie);
java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie解决方法的更多相关文章
- java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie
https://blog.csdn.net/cml_blog/article/details/52135115 当项目中使用单点登录功能时,通常会使用cookie进行信息的保存,这样就可以在多个子域名 ...
- 【Cookie】java.lang.IllegalArgumentException An invalid character [32] was present in the Cookie value
创建时间:6.30 java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie va ...
- java.lang.IllegalArgumentException: An invalid character [34] was present in the Cookie value
java.lang.IllegalArgumentException: An invalid character [34] was present in the Cookie value at org ...
- cookie实例---显示上一次访问的时间与java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value
创建Cookie,名为lasttime,值为当前时间,添加到response中: 在A.jsp中获取请求中名为lasttime的Cookie: 如果不存在输出“您是第一次访问本站”,如果存在输出“您上 ...
- 异常java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value
通过HttpServletResponse的addCookie(Cookie cookie)向客户端写cookie信息,这里使用的tomcat版本是8.5.31,出现如下报错: java.lang.I ...
- java.lang.IllegalStateException: Cannot forward after response has been committed的一个情况解决方法
java.lang.IllegalStateException: Cannot forward after response has been committed xxx.xxx.doPost(upd ...
- java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result异常的解决方法
今天在写一个JAVA程序的时候出现了异常:java.lang.ArithmeticException: Non-terminating decimal expansion; no exact repr ...
- tomcat 8.5 及其 9.0 response写cookie 设置damain为 [.test.com] 出错 An invalid domain [.test.com] was specified for this cookie
抛出异常: java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cooki ...
- An invalid domain [.test.com] was specified for this cookie 原因分析
java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie 以上博客 ...
随机推荐
- maven项目中使用redis集群报错: java.lang.NumberFormatException: For input string: "7001@17001"
解决:由于redis集群的采用的版本是2.7的,在maven的pom.xml中将jedis的版本改成2.9的就可以了
- HTTP 错误 500.19 - Internal Server Error 无法读取配置节 system.serviceModel 因为它缺少节声明
服务器环境:Windows Server2008 R2 Enterprise 配置 IIS 的时候报错. 错误信息: HTTP 错误 500.19 - Internal Server Error无法访 ...
- js 画布与图片的相互转化(canvas与img)
使用js将图片拷贝进画布 //将图片对象转化为画布,返回画布function ImageToCanvas(image) { var canvas = document.createElement(&q ...
- vue动态组件切换(选项卡)
vue的动态组件 <template :is='变量'></template> 可以通过改变变量,来改变template的替换内容.达到选项卡的功能 如果想要切换保持不重新创建 ...
- vue里computed的get和set
computed里的对象有get和set方法. get是当该对象所依赖的变量发生变化是执行,重新returncomputed结果. set是该对象的值变化时会执行,并且将变化的结果作为参数传进set里 ...
- 使用 ASP.NET SignalR实现实时通讯
ASP.NET SignalR 是为 ASP.NET 开发人员提供的一个库,可以简化开发人员将实时 Web 功能添加到应用程序的过程.实时 Web 功能是指这样一种功能:当所连接的客户端变得可用时服务 ...
- 有关vue开发的小经验
注册登录已经成为布局的常事,这里为大家推荐两种超级好用的布局display:flex;justify-content:center;这个可以解决水平居中的疑难杂症 align-center:cente ...
- SpringBoot:四种读取properties文件的方式
前言 在项目开发中经常会用到配置文件,配置文件的存在解决了很大一份重复的工作.今天就分享四种在Springboot中获取配置文件的方式. 注:前三种测试配置文件为springboot默认的applic ...
- python语法_变量及命名规则
变量:存储信息的,日后被调用,修改操作 常量:固定不变的量,字母大写 变量命名规则: 1 有字母,数字以及下划线等符号组成 2 区分大小写 3 不能使用数字开头,不能含有特殊字符和空格 4 不能使用 ...
- 个人小爱好:Operating System: three easy pieces—第6章第3小节问题2#进程间的切换
问题2#:进程间的切换 直接执行的下一个问题是如何实现进程的切换.进程的切换按理说是挺简单的,对吧?不就是决定哪一个进程应该停止,哪一进程应该开始而已,才多大点事情啊?但,事实上这还真的有点棘手:尤其 ...