JSP获取客户端机器名的疑问?

本文探讨了使用Java的HTTP请求处理中获取客户端真实主机名的方法。通过分析request.getRemoteHost()方法的实际表现,发现其通常返回的是IP地址而非预期的客户端主机名。文章进一步讨论了在不同场景下获取客户端主机名的有效途径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

经过测试:

request.getRemoteAddr(); 获得客户端的IP地址
request.getRemoteHost();也只是获取IP,跟getRemoteAddr()方法结果一样
官方API说这个方法是获取获得客户端电脑的名字,我测试没有获得过机器名称。
英语解释如下:
getRemoteHost
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. For HTTP servlets, same as the value of the CGI variable REMOTE_HOST.

Returns:
a String containing the fully qualified name of the client


现在我想获得客户端电脑的名字?有什么好方法
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值