Is there a way to get the client's IP address inside an struts2 action method?
I have implemented both SesionAware
and RequestAware
interfaces, but these two inject only the session and request maps.
Is there a way to get the client's IP address inside an struts2 action method?
I have implemented both SesionAware
and RequestAware
interfaces, but these two inject only the session and request maps.
You can try ServletRequest.getRemoteAddress() API call to get client or last proxy's IP address. This is part of Servlet API and not Struts2 specific.
Try request.getRemoteAddress(). This will give you the client IP. If the request is coming through a proxy server, then you will get only the ip of the proxy server.