Jsp to obtain the Client ip address. jsp to obtain the Client ip Address
This example describes how to use jsp to obtain the IP address of a client. We will share this with you for your reference. The details are as follows:
Public static 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. getHeader ("HTTP_CLIENT_IP");} if (ip = null | ip. length () = 0 | "unknown ". equalsIgnoreCase (ip) {ip = request. getHeader ("HTTP_X_FORWARDED_FOR");} if (ip = null | ip. length () = 0 | "unknown ". equalsIgnoreCase (ip) {ip = request. getRemoteAddr ();} return ip ;}
I hope this article will help you with JSP program design.