我正在尝试使用以下代码在jsp页面中获取我的IP地址:
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
这打印0:0:0:0:0:0:0:1,而不是我的IP地址。这是什么?为什么不显示我的IP地址?
由于
答案 0 :(得分:1)
这是你的IP地址,但不是IPv4(xx.xx.xx.xx)而是IPv6(xx:xx:xx:xx:xx:xx:xx:xx)
编辑:如果您的系统正在将IPv6映射到IPv6,您可以通过阅读this来推断算法在它们之间进行更改
答案 1 :(得分:-1)
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:// localhost :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