To get the IP address, we use the HttpServletRequestobject method getRemoteAddr. But this will only give you the client’s public IP address, especially when the client is behind the proxy server.
String ipAddress = request.getRemoteAddr();
IP- X-FORWARDED-FOR HTTP.
request.getHeader("X-FORWARDED-FOR");
X-FORWARDED-FOR