Here are 2 methods for getting client’s IP address in Servlet:

HttpServletRequest.getRemoteAddr method returns IP of the client that sends request.

HttpServletRequestgetRemoteHost method returns the hostname of the client that is sending the request. However, it may return an empty string if hostname is unknown.

BY Best Interview Question ON 19 Jan 2019