我想下面的代碼,讓我的IP地址在JSP頁面中:request.getRemoteAddr()返回0:0:0:0:0:0:0:1在JSP頁面
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
這將打印0:0:0:0:0:0:0:1,而不是我的IP地址。這是什麼被認爲是?爲什麼不顯示我的IP地址?
感謝
我想下面的代碼,讓我的IP地址在JSP頁面中:request.getRemoteAddr()返回0:0:0:0:0:0:0:1在JSP頁面
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
這將打印0:0:0:0:0:0:0:1,而不是我的IP地址。這是什麼被認爲是?爲什麼不顯示我的IP地址?
感謝
JSP代碼:
<html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%
out.println("Your Host IP address is " + request.getRemoteHost()+"</br>");
out.println("Your Addr address is " + request.getRemoteAddr()+"</br>");
out.println("Your Port Post address is " + request.getRemotePort()+"</br>");
%>
</body>
</html>
使用http:// 127.0.0.1:8081/hello.jsp中得到結果:
Hello World!
Your Host IP address is 0:0:0:0:0:0:0:1
Your Addr address is 0:0:0:0:0:0:0:1
Your Port Post address is 32432
使用http:// 本地主機:8081/hello.jsp中得到結果:
Hello World!
Your Host IP address is 0:0:0:0:0:0:0:1
Your Addr address is 0:0:0:0:0:0:0:1
Your Port Post address is 32432
您提供的結果對於這兩個請求都是完全相同的。這就是你想說的,沒有區別? – sorrymissjackson
是的,我經過仔細觀察後,沒有什麼區別......大聲笑 – Wuaner
嘗試增加'-Djava .net.preferIPv4Stack = true'到您的servlet容器啓動腳本 – Reimeus
更好的回答:http://stackoverflow.com/questions/17964297/using-request-getremoteaddr-returns-00000001 –