首页 > 编程 > JSP > 正文

jsp获取客户端IP地址的方法

2020-07-27 21:29:20
字体:
来源:转载
供稿:网友

本文实例讲述了jsp获取客户端IP地址的方法。分享给大家供大家参考,具体如下:

public static String getIpAddr(HttpServletRequest request) {   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();  }  return ip;}

希望本文所述对大家JSP程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表