Tomcat 8.5 cookie-domain的问题
java.lang.IllegalArgumentException: An invalid domain [.xxxx.com] was specified for this cookie
tomcat8.5较之前版本不需要.了
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
//tomcat8.5以后去除.
//domainName = "." + domains[len - 3] + "." + domains[len - 2] + "." + domains[len - 1];
domainName = domains[len - 3] + "." + domains[len - 2] + "." + domains[len - 1];
} else if (len <= 3 && len > 1) {
// xxx.com or xxx.cn
//tomcat8.5以后去除.
//domainName = "." + domains[len - 2] + "." + domains[len - 1];
domainName = domains[len - 2] + "." + domains[len - 1];
} else {
domainName = serverName;
}
}
return domainName;
}