假如用代理服务器,request.getRemoteAddr(); 只能得到代理服务器地址 以下方法是得到正确所有ip的方法 在jsp声明这个函数 <%!public String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; }%> 嵌入jsp网页中,然后用<%String ip=getIpAddr(request);%>得到访问者ip ip就是访问者的ip,你保存到数据库或者缓存中,就由你自己了