开发问题解决志

2014.5.5

     获取客户端真实ip地址出现问题,解答如下:

    

When you have NAT (Network Address Translation) device before your servlet container request.getRemoteAddr() returns the address of NAT , since it initiate a new connection.

To solve your problem you should configure you NAT to send in a header the IP of the original client. Then, to take the header from the request. In case you configure in NAT X-Forwarded-For header use this code: request.getHeader("X-Forwarded-For")

You function is correct, you can use it when you configure NAT.

   

原文地址:https://www.cnblogs.com/elearn007/p/3709819.html