在服务器端获得客户端ip怎么获得
我知道一个 方法request.getRemoteAddr()
可是我不知道 request 从哪里加进来
有没知道的
写在普通类里
有没谁知道啊
或者有没谁有其他方法啊! 急啊!!!!!1
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null
------解决方案-------------------------------------------------------- ip.length() == 0 ip.length() == 0 ip.length() == 0 "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null ip.length() == 0 楼上的说得漏了好几种情况,某些情况下还是获取的不正确,我下面的比较全几乎涵盖了所有的客户端形式,完全可以使用
public static String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (ip == null "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null
ip.length() == 0
/**
*
*/
package com.ccit.ejtg.util;
import javax.servlet.http.HttpServletRequest;
/**
* @描述 获得IP4
* @author XYY
* @time 2010-3-22上午09:06:14
* @version 1.0
* @类名 IP4.java
*/
public class IP4 {
public static String getIP4(HttpServletRequest request){
String ip = request.getHeader("x-forwarded-for");
if (ip == null "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
}