If a single servlet serves data from two domains example1.com and example2.com, how do you retrieve the domain information from the request in a Java servlet?
The purpose is to perform different actions depending on the domain.
If a single servlet serves data from two domains example1.com and example2.com, how do you retrieve the domain information from the request in a Java servlet?
The purpose is to perform different actions depending on the domain.
Very easy, javax.servlet.ServletRequest.getServerName(). It also provides further methods to retrieve request information, getScheme(), getServerPort()...
Edit: If you have a web server guarding your application server, it must be configured to support this, otherwise getServerName() returns the name of your application server which may not be what you want...