2013-06-13 150 views

回答

7

使用URI

final URI uri = request.getURL().toURI(); 
final String hostname = uri.getHost(); 

然后在hostname操作(像hostname.split("\\.")[0],例如)。

+0

的子域名?例如, – Amruta

+0

'test.company.com';该URI的主机名部分;) – fge

+0

感谢它的工作。 – Amruta

0
Pattern subDomainPattern = Pattern.compile("^(.+)\\.company\\.com$"); 
Matcher matcher = subDomainPattern.matcher(httpServletRequest.getServerName()); 
if (matcher.find()) { 
    System.out.println(matcher.group(1)); 
} 

假设你只想要得到什么将存储在这里的主机名company.com