java获取用户ip
/**
* @title 获取访问用户的真实IP地址
* @param request
* @return ip
*/
public static String getIpAddr(HttpServletRequest request)
{
String addr = request.getHeader("x-forwarded-for");
if (addr == null || addr.length() == 0 || "unknown".equalsIgnoreCase(addr))
{
addr = request.getHeader("Proxy-Client-IP");
}
if (addr == null || addr.length() == 0 || "unknown".equalsIgnoreCase(addr))
{
addr = request.getHeader("WL-Proxy-Client-IP");
}
if (addr == null || addr.length() == 0 || "unknown".equalsIgnoreCase(addr))
{
addr = request.getRemoteAddr();
}
return addr;
}