seam实现在线用户信息的统计以及在用户IP的获取

seam实现在线用户信息的统计以及在用户IP的获取
public String getIp() {
try {
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fc
.getExternalContext().getRequest();
return getIpAddr(request);
} catch (Exception e) {
e.printStackTrace();
return "";
}
}

public String getIpAddr(HttpServletRequest request) {
String ip = null;
Enumeration enu = request.getHeaderNames();
while (enu.hasMoreElements()) {
String name = (String) enu.nextElement();
if (name.equalsIgnoreCase("X-Forwarded-For")) {
ip = request.getHeader(name);
} else if (name.equalsIgnoreCase("Proxy-Client-IP")) {
ip = request.getHeader(name);
} else if (name.equalsIgnoreCase("WL-Proxy-Client-IP")) {
ip = request.getHeader(name);
}

if ((ip != null) && (ip.length() != 0))
break;

}
if ((ip == null) || (ip.length() == 0))
ip = request.getRemoteAddr();
return ip;
}

你可能感兴趣的:(seam)