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
2010-06-21 06:51:34
+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
2010-06-21 07:08:47
+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
2010-06-21 11:47:38