How do I get the remote address of a client in servlet?

前端 未结 10 2048
刺人心
刺人心 2020-11-22 07:32

Is there any way that I could get the original IP address of the client coming to the server? I can use request.getRemoteAddr(), but I always seem to get the IP

10条回答
  •  深忆病人
    2020-11-22 08:09

    "x-forwarded-for" request header contains the original client IP if using a proxy or a load balancer. But I think not all proxies/lb adds this header.

    Here some java code to parse the header: http://www.codereye.com/2010/01/get-real-ip-from-request-in-java.html

    If this header is not present then I would proceed as @Bozho suggests

提交回复
热议问题