ServletRequest 中的 ServerName 与 LocalName

发布于 2025-01-09 12:27:35 字数 530 浏览 0 评论 0原文

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.

我认为两者都是同一实体的主机名。

  1. 不是这样吗?
  2. 服务器和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.

  1. Is it not so?
  2. Also what is difference between server and IP interface?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦过后 2025-01-16 12:27:35

它们并不相同:

  • serverName 是 HTTP 客户端请求的虚拟主机的名称(参见 Host 标头)。这可以被 proxyName 覆盖连接器的值,RemoteIpValveRewriteValve
  • 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 the proxyName value of the connector, the RemoteIpValve or the RewriteValve,
  • localName is obtained through a reverse lookup of the local IP (the details depend on the OS).

Basically always use serverName to generate URLs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文