views:

34

answers:

3

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.

A: 

Have you tried ServletRequestAware?

leonbloy
A: 

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.

Purush Rudrakshala
+1  A: 

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.

Sujith