I have a java Spring web application, deployed on an Apache server, in which I wish to capture IP address of client using the following code.
public static String getIpFromRequest(HttpServletRequest request){
String remoteAddr = "";
if (request != null) {
remoteAddr = request.getHeader("X-FORWARDED-FOR");
if (remoteAddr == null || "".equals(remoteAddr)) {
remoteAddr = request.getRemoteAddr();
}
}
return remoteAddr;
}
By this code I'm getting the same IP address for every client. I have referred all stackoverflow questions, but they suggested same above code. Please suggest possible way.