[英]Client System Host Name is not captureing using request.getRemoteHost()
[英]Does request.getRemoteHost() return the IP of browser host?
<HTML>
<BODY>
<%
// This scriptlet declares and initializes "date"
System.out.println( "Evaluating date now" );
java.util.Date date = new java.util.Date();
%>
Hello! The time is now
<%
out.println( date );
out.println( "<BR>Your machine's address is " );
out.println( request.getRemoteHost());
%>
</BODY>
</HTML>
在上面的JSP代碼中,我認為request.getRemoteHost()
將返回瀏覽器主機的IP地址。 但是,它返回的內容類似於: 0:0:0:0:0:0:0:1
。 有什么問題?
getRemoteHost()返回發送請求的客戶端的標准名稱。
getRemoteAddr()返回發送請求的客戶端的Internet協議(IP)地址。
request.getRemoteAddr()
返回組件的IP地址,而request.getRemoteHost()
嘗試撤消主機名。 如果主機名為空 ,則它將嘗試檢索IP地址,就像getRemoteAddr()的工作方式一樣。
它確實是運行瀏覽器的計算機的IP,因此它將返回127.0.0.1
,或者在您的情況下返回::1
,這是IPv6中的localhost。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.