sâmbătă, 28 martie 2015

[OmniFaces utilities (2.3/2.0)] Get the Internet Protocol (IP) address of the client that sent the request


[OmniFaces utilities] The getRemoteAddr() method returns the Internet Protocol (IP) address of the client that sent the request. This will first check the X-Forwarded-For request header and if it's present, then return its first IP address, else just return HttpServletRequest#getRemoteAddr() unmodified.

Starting with OmniFaces 2.3 this method is available in Servlets utility class also as, Servlets#getRemoteAddr().

Method:

OmniFaces 2.3OmniFaces 2.0
Usage:

import org.omnifaces.util.Faces;
...
// 'remoteAddr' may be '0:0:0:0:0:0:0:1'
String remoteAddr = Faces.getRemoteAddr();

Niciun comentariu:

Trimiteți un comentariu