'ServerName vs LocalName in ServletRequest
There are 2 attributes in ServletRequest and would like to understand the difference between the 2. According to definition in https://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html,
getServerName(): Returns the host name of the server to which the request was sent.
getLocalName(): Returns the host name of the Internet Protocol (IP) interface on which the request was received.
I think both are the hostnames of same entity here.
- Is it not so?
- Also what is difference between server and IP interface?
Solution 1:[1]
They are not the same:
serverNameis the name of the virtual host requested by the HTTP client (cf.Hostheader). This can be overridden by theproxyNamevalue of the connector, theRemoteIpValveor theRewriteValve,localNameis obtained through a reverse lookup of the local IP (the details depend on the OS).
Basically always use serverName to generate URLs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
