/**
* 获取IP公共方法
* @param req
* @return
*/
public static String getIP(HttpServletRequest req) {
String ipStr = req.getHeader(" x-forwarded-for ");
if (ipStr == null || ipStr.length() == 0
|| " unknown ".equalsIgnoreCase(ipStr)) {
ipStr = req.getHeader(" Proxy-Client-IP ");
}
if (ipStr == null || ipStr.length() == 0
|| " unknown ".equalsIgnoreCase(ipStr)) {
ipStr = req.getHeader(" WL-Proxy-Client-IP ");
}
if (ipStr == null || ipStr.length() == 0
|| " unknown ".equalsIgnoreCase(ipStr)) {
ipStr = req.getRemoteAddr();
}
return ipStr;
}
* 获取IP公共方法
* @param req
* @return
*/
public static String getIP(HttpServletRequest req) {
String ipStr = req.getHeader(" x-forwarded-for ");
if (ipStr == null || ipStr.length() == 0
|| " unknown ".equalsIgnoreCase(ipStr)) {
ipStr = req.getHeader(" Proxy-Client-IP ");
}
if (ipStr == null || ipStr.length() == 0
|| " unknown ".equalsIgnoreCase(ipStr)) {
ipStr = req.getHeader(" WL-Proxy-Client-IP ");
}
if (ipStr == null || ipStr.length() == 0
|| " unknown ".equalsIgnoreCase(ipStr)) {
ipStr = req.getRemoteAddr();
}
return ipStr;
}
获取客户端IP地址

1074

被折叠的 条评论
为什么被折叠?



