tags:

views:

82

answers:

3

In JSP page I want to get IP address of user who view the page. How can ?

+5  A: 
<%= request.getRemoteAddr() %>

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR.

Lauri Lehtinen
+3  A: 

Just to add to @Lauri's answer.

If the request came via a proxy, there should be a "Via" header in the request.

However, there is no way to figure out what the real client IP address if there are any intermediate proxies. And a lot of peoples' browsers use proxies, whether or not they are aware of it.

Stephen C
+1  A: 

Since scriptlets (those <% %> things) are discouraged since a decade, here's the EL solution:

<p>Your IP address is: ${pageContext.request.remoteAddr}</p>

If you actually intend to use this for some business purposes rather than displaying purposes, then you should be using a servlet. It's then available by HttpServletRequest#getRemoteAddr().

BalusC