繁体   English   中英

为什么getRemoteHost()在部署应用程序时会返回IP地址?

[英]Why does getRemoteHost() return an IP address upon deploying the application?

在我的开发环境中,getRemoteHost()成功返回客户端的PC /计算机名称。 但是,一旦我将应用程序部署到生产环境中,getRemoteHost()就会突然返回IP地址。

为了使其始终返回PC /计算机名称,需要采取什么措施? 它是在WAS 7.0上运行的Java Web应用程序。

从Java API

java.lang.String getRemoteHost()

Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address.

编辑:您可以尝试像这样解析主机名

InetAddress addr = InetAddress.getByName(ipString);
String host = addr.getHostName();
System.out.println(host);

其中ipString是从getRemoteHost()调用返回的IP的点字符串形式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM