日期:2014-05-18  浏览次数:20824 次

j2ee得到client的IP地址
	public static String getIp(HttpServletRequest req) {
		try {
			if (req == null) {
				return null;
			}
			String ip_for = req.getHeader(" x-forwarded-for ");
			String ip_client = req.getHeader(" http_client_ip ");
			String un = " unknown ";

			if (ip_for != null && !ip_for.equalsIgnoreCase(un)
					&& ip_for.trim().length() > 0) {
				return ip_for;
			} else if (ip_client != null && !ip_client.equalsIgnoreCase(un)
					&& ip_client.trim().length() > 0) {
				return ip_client;
			} else {
				return req.getRemoteAddr();
			}
		} catch (Exception e) {
			LOGGER.error("Error: get ip failure : " + e.getMessage());
		}
		return null;
	}

?