欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jsp获取客户端IP地址的方法

程序员文章站 2022-05-18 12:38:45
本文实例讲述了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程序设计有所帮助。