This article illustrates how JSP obtains the client IP address. Share to everyone for your reference, specific 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.