I am late here, but this might help someone looking for the answer. Typically servletRequest.getRemoteAddr() works.
In many cases your application users might be accessing your web server via a proxy server or maybe your application is behind a load balancer.
So you should access the X-Forwarded-For http header in such a case to get the user’s IP address.
e.g. String ipAddress = request.getHeader(“X-FORWARDED-FOR”);
Hope this helps.