apache-tomcat-9.0.24部署到服务器会发生这样的问题
作者:互联网
apache-tomcat-9.0.24部署到服务器会发生这样的问题
java.lang.IllegalArgumentException: An invalid domain [.tencent.xxx.com] was specified for this cookie
解决方法:
找到 CookieUtil.java 把 domainName=… 前面的点号去掉删去就可以了。
private static final String getDomainName(HttpServletRequest request) {
String domainName = null;
String serverName = request.getRequestURL().toString();
if (serverName == null || serverName.equals("")) {
domainName = "";
} else {
serverName = serverName.toLowerCase();
serverName = serverName.substring(7);
final int end = serverName.indexOf("/");
serverName = serverName.substring(0, end);
if (serverName.indexOf(":") > 0) {
String[] ary = serverName.split("\\:");
serverName = ary[0];
}
final String[] domains = serverName.split("\\.");
int len = domains.length;
if (len > 3 && !isIp(serverName)) {
// www.xxx.com.cn
domainName = "." + domains[len - 3] + "." + domains[len - 2] + "." + domains[len - 1];
} else if (len <= 3 && len > 1) {
// xxx.com or xxx.cn
domainName = "." + domains[len - 2] + "." + domains[len - 1];
} else {
domainName = serverName;
}
}
return domainName;
}
- 规则
- 必须是1-9、a-z、A-Z、. 、- (注意是-不是_)这几个字符组成
- 必须是数字或字母开头 (所以以前的cookie的设置为.XX.com 的机制要改为 XX.com 即可)
- 必须是数字或字母结尾
- cookie.setDomain(".test.com");在rfc6265标准中应该改为cookie.setDomain(“test.com”)
由此问题解决。
标签:24,String,tomcat,domainName,serverName,len,domains,apache,com 来源: https://blog.csdn.net/Kou_Lu/article/details/104711524