jsp获取客户端IP地址的方法
程序员文章站
2024-02-03 10:25:52
本文实例讲述了jsp获取客户端ip地址的方法。分享给大家供大家参考,具体如下:
public static string getipaddr(httpservle...
本文实例讲述了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程序设计有所帮助。