There are some domain-name-registrars/DNS-providers that allow you to set up a
wildcard "host" where their domain name servers will dynamically redirect HTTP
requests. For example:
http://*.domain.tld/
could be redirected to something like
http://mywildcardhost.domain.tld/%SERVER_NAME%/
where "%SERVER_NAME%" would take on the whatever "host" was originally used in
the HTTP request. It's then a simple task of using a wildcard <url-pattern/>
servlet mapping ("/*" in this example) to direct the request accordingly.
This obviates the need to customize Tomcat code. However, you'll probably need
a nominal monetary outlay to use the services of said DDNS provider.
Read more: http://www.changeip.com/