//ip地址的获取:非原创,之前在其他地方看到,拿过来备份下:
public static String getIPAddress(HttpServletRequest request) { String ip = null; String ipAddresses = request.getHeader("X-Forwarded-For"); if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ipAddresses = request.getHeader("Proxy-Client-IP"); } if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ipAddresses = request.getHeader("WL-Proxy-Client-IP"); } if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ipAddresses = request.getHeader("HTTP_CLIENT_IP"); } if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ipAddresses = request.getHeader("X-Real-IP"); } if(ipAddresses != null && ipAddresses.length() != 0) { ip = ipAddresses.split(",")[0]; } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ip = request.getRemoteAddr(); } return ip; }