当前位置:首页 > 开发 > Web前端 > JavaScript > 正文

jsp中获取客户端的IP

发表于: 2012-04-20   作者:随便小屋   来源:转载   浏览:
jsp
摘要: 1.public static String getIpAddr(HttpServletRequest request) {   2.        String ip = request.getHeader("X-Forwarded-For");   3.&nbs
1.public static String getIpAddr(HttpServletRequest request) {  
2.        String ip = request.getHeader("X-Forwarded-For");  
3.        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
4.            ip = request.getHeader("Proxy-Client-IP");  
5.        }  
6.        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
7.            ip = request.getHeader("WL-Proxy-Client-IP");  
8.        }  
9.        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
10.            ip = request.getHeader("HTTP_CLIENT_IP");  
11.        }  
12.        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
13.            ip = request.getHeader("HTTP_X_FORWARDED_FOR");  
14.        }  
15.        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
16.            ip = request.getRemoteAddr();  
17.        }  
18.        return ip;  
19.    }  

jsp中获取客户端的IP

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号