I'm trying to find a Java method that would get a ServletRequest and finds the IP address for that request. Something like this method that I found but would receive a ServletRequest instead of HTTPServletRequest :
How can I get the IP address from a ServletRequest, not a HTTPServletRequest ?
3.6k Views Asked by sophie96 At
2
There are 2 best solutions below
0

The ServletRequest also provides the method java.lang.String getRemoteAddr()
see https://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getRemoteAddr() for more details.
I'd check if the request is an HTTP request, if so, use the method proposed in the other question. Otherwise, I'd trust the method
getRemoteAddr()
blindly.