亲宝软件园·资讯

展开

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

5iasp 人气:9
想了解jsp获取客户端IP地址的方法的相关内容吗,5iasp在本文为您仔细讲解jsp获取客户端IP地址的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:jsp,客户端,IP地址,下面大家一起来学习吧。

本文实例讲述了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程序设计有所帮助。

加载全部内容

相关教程
猜你喜欢
用户评论