在 Servlet 中,可用通过以下方法来获取服务端的 IP 地址和端口。

1
2
3
4
InetAddress iAddr = InetAddress.getLocalHost();
String host = iAddr.getHostAddress();

int port = request.getLocalPort();
TAGS