How to get the IP address and port of the server in the servlet

In a servlet, you can obtain the IP address and port of the server by using the following methods.

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

int port = request.getLocalPort();

本文标题:How to get the IP address and port of the server in the servlet

文章作者:Morning Star

发布时间:2021年10月10日 - 11:10

最后更新:2022年01月24日 - 19:01

原始链接:https://www.mls-tech.info/java/java-get-ip-port-in-servlet-en/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。