日期:2014-05-20 浏览次数:20718 次
/**1
* 获取客户端Ip地址
*
* @return
*/
protected String getIpAddr(HttpServletRequest request) {
// 通过请求头获取ip地址
String ip = request.getHeader("x-forwarded-for");
// 判断ip地址是否是代理地址
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
// 判断ip地址是否是代理地址
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
// 判断ip地址是否是代理地址
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}