• 获取客户端ip


    public String getRemortIP(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;
        }

    public String getRemortIP(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();

            }

            returnip;

        }

  • 相关阅读:
    Java线程状态和关闭线程的正确姿势
    Eclipse最全的编码设置
    Maven中的src/test/java颜色不正常
    web.xml 各版本的 Schema 头部声明
    程序员面试系列
    几款强大的网页生成工具
    endnoteX9批量导入enw
    关于Ubuntu16.04里安装elasticsearch-head显示集群健康值未连接的问题
    U盘做了系统盘,写入如硬盘映像过程中终止,怎么格式化硬盘重新写入?
    使用jupyter notebook出现kernel error
  • 原文地址:https://www.cnblogs.com/tianxuwei/p/10478983.html
Copyright © 2020-2023  润新知