Original: http://blog.csdn.net/mydwr/article/details/9357187
/*** Get Visitor ip* * In general, use REQUEST.GETREMOTEADDR (), but after the reverse proxy software such as Nginx, this method will fail. * * This method first obtains the X-real-ip from the header, if it does not exist then obtains the first IP from the X-forwarded-for (with, splits), * if does not already exist then calls the request. GETREMOTEADDR (). * * @paramrequest*@return*/ Public StaticString getipaddr (HttpServletRequest request)throwsexception{string IP= Request.getheader ("X-real-ip");if(! Stringutils.isblank (IP) &&! " Unknown. Equalsignorecase (IP)) {returnIP;} IP= Request.getheader ("X-forwarded-for");if(! Stringutils.isblank (IP) &&! " Unknown. Equalsignorecase (IP)) {//multiple reverse proxies will have more than one IP value, the first being a real IP. intindex = Ip.indexof (', ');if(Index! =-1) {returnIp.substring (0, index);} Else {returnIP;}} Else {returnrequest.getremoteaddr ();}}
Java Get Client Access IP