ServletRequest 中的 ServerName 与 LocalName
ServletRequest中有2个属性,想了解这2个属性之间的区别。 根据 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.
我认为两者都是同一实体的主机名。
- 不是这样吗?
- 服务器和IP接口有什么区别?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们并不相同:
serverName
是 HTTP 客户端请求的虚拟主机的名称(参见Host
标头)。这可以被proxyName
覆盖连接器的值,RemoteIpValve
或RewriteValve
,localName
通过本地反向查找得到IP(详细信息取决于操作系统)。基本上总是使用
serverName
来生成 URL。They are not the same:
serverName
is the name of the virtual host requested by the HTTP client (cf.Host
header). This can be overridden by theproxyName
value of the connector, theRemoteIpValve
or theRewriteValve
,localName
is obtained through a reverse lookup of the local IP (the details depend on the OS).Basically always use
serverName
to generate URLs.