Get Application Server name or ip and port in Java
java, web-applications, websphere
Solution
You can use `ServletRequest#getLocalXXX()` methods for this.
- `ServletRequest#getLocalName()` returns local hostname.
- `ServletRequest#getLocalAddr()` returns local IP.
- `ServletRequest#getLocalPort()` returns local port.
Problem
We would like to identify and display the server and port that a Java application is running on that is behind a proxy web server. This means that getServerName() and getServerPort() return the server name of the proxy and its port (80). We have two application server instances running on a single physical box and therefore have two active ports per box i.e. 9080, 9081. What I'd like to have is `<Application Server Name>:<Application Server Port>` displayed. Any ideas? I'm a complete Java noob, sorry if this is a basic question.