In JSP, the method of obtaining the IP address of the client is: Request.getremoteaddr (), which is effective in most cases. But in the adoption of APACHE,SQUID and other reverse proxy software can not get to the client's real IP address. If the reverse proxy software is used, the IP address obtained using the REQUEST.GETREMOTEADDR () method is 127.0.0.1 or 192.168.1.110, not the real IP of the client.
A way to see in the Internship company:
/** * Get IP Address * @return/protected String getipaddr () {HttpServletRequest request = Servletactioncontext.getrequest (); S Tring 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; }