title: what is the right way to get request's ip
body: <p>I find some different ways to get ip in servlet. but i don't know which one is right and why.</p>
  
  <p>1:  </p>
  
  <pre><code>request.getHeader( "X-Real-IP" )
  </code></pre>
  
  <p>2:         </p>
  
  <pre><code>  String ip = request.getHeader("X-Forwarded-For"); 
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
          ip = request.getHeader("Proxy-Client-IP");  
      }  
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
          ip = request.getHeader("WL-Proxy-Client-IP");  
      }  
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
          ip = request.getHeader("HTTP_CLIENT_IP");  
      }  
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
          ip = request.getHeader("HTTP_X_FORWARDED_FOR");  
      }  
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
          ip = request.getRemoteAddr();  
      } `
  </code></pre>
  
  <p>3:</p>
  
  <pre><code> String ip=request.getHeader("x-forwarded-for");
                  if(ip==null){
                      ip=request.getRemoteAddr();
                  }
                  String ips[]=ip.split(",");`
                                  ip=ips[0];
  </code></pre>