title: Getting null value for request.getHeader("X-FORWARDED-FOR") while retrieving client IP address in java?
body: <p>I have deployed my web application on Tomcat 6.0 in machine having ip address 10.xx.xx.90. Then i am making a http request(from browser) to this app from m/c having ip address (10.xx.xx.56).</p>
  <p>I am trying to get the IP address of client(10.xx.xx.56) in my app using the below code. But I am getting null value for request.getHeader(&quot;X-FORWARDED-FOR&quot;) where as request.getRemoteAddr() returns the ip address of the machine on which the application is deployed i.e 10.xx.xx.90.</p>
  <p>But, if I make a http call to the application from standalone java program I am able to get the client m/c ip address. So, what is the correct way to get the client IP address. Do I need to configure something in my tomcat ??</p>
  <pre><code>   String ipAddress = request.getHeader(&quot;X-FORWARDED-FOR&quot;);  
         if (ipAddress == null) {  
         ipAddress = request.getRemoteAddr();  
     }
  </code></pre>