论坛首页 Java企业应用论坛

在java中获取客户端真实的IP地址

浏览 2744 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2008-08-26  
public static String getRemoteAddress(HttpServletRequest request){
    String ip = request.getHeader("x-forwarded-for");
    if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getHeader("Proxy-Client-IP");
    if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getHeader("WL-Proxy-Client-IP");
    if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getRemoteAddr();
    return ip;
}
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics