How to Handle Virtual Hosts and Multiple IP Addresses?
A web server may listen on several IP addresses, and each IP address may be used for several host names (virtual hosts). The Servlet Specification established the following rules for virtual hosts:
- Virtual servers can not share ServletContexts. If you configure your server to use virtual hosts, you usually need to deploy your application for each virtual host separately.
- A web container can use a single ServletContext for several addresses or names if they all behave identically (and thus behave like a single server).
- Use the ServletRequest's getLocalAddr method to find out on which address a request has been received.
- Read the Host header value with getHeader to find out which virtual host name was requested by the client (note that some primitive clients may not send a Host).

