This information is based on queries, not strictly application-based. This can be changed upon request. All you have during servlet initialization is the ServletContext , which in turn offers methods like getInitParameter() . You can use it to access wide application settings.
So, it’s best to manually set the server name as the context parameter in web.xml
<context-param> <param-name>serverName</param-name> <param-value>foo</param-value> <context-param>
so that you can get it like this in the init() servlet method:
String serverName = getServletContext().getInitParameter("serverName");
Another (not recommended) option is to set it as a display name in web.xml
<display-name>foo</display-name>
so that you can get it like this:
String serverName = getServletContext().getServletContextName();
Balusc
source share