jimingminlovefly

统计

最新评论

案例-java获取访客ip地址

public 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.getRemoteAddr();
     }
     //返回一串ip值的话,取第一个
     if(ip.contains(",")){
      ip = ip.substring(0, ip.indexOf(","));
     }
     return ip;
 }

posted on 2011-11-09 11:41 计明敏 阅读(552) 评论(1)  编辑  收藏 所属分类: java

评论

# re: 案例-java获取访客ip地址 2014-08-06 16:15 tt

tttt  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: