The "root domain":

For the "root domain", you'll have to work through the String returned from getServerName(). This is necessary because the Servlet would have no way of knowing ahead of time what you call "host" or what is just a domain like .com (it could be a machine called com in your network - and not just a suffix -, who knows?).

For the pattern you gave (one third+secondlevel+com/net), the following should get what you need: