Not getting IP address of Client in Java Spring Web Application

Viewed 449

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.

0 Answers
Related