45fan.com - 路饭网

搜索: 您的位置主页 > 电脑频道 > 编程代码 > 阅读资讯:如何通过jsp获取客户端IP地址?

如何通过jsp获取客户端IP地址?

2016-03-05 16:31:38 来源:www.45fan.com 【

如何通过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程序设计有所帮助。


本文地址:http://www.45fan.com/bcdm/41369.html
Tags: 获取 JSP 客户端
编辑:路饭网
推广内容
推荐阅读
热门推荐
推荐文章
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部