The request object is passed as a Java argument to the servlet method generated from your JSP. Argument name ... wait ... request .
So, you should be able to reference it in the scriptlet built into your JSP; eg.
<% InetAddress addr = request.getRemoteAddr(); // blah blah blah %>
It's debatable whether this kind of thing is worth doing in the JSP. It is generally accepted as "best practice" that JSP should only be used to format output. The webapp business logic must reside in the controller servlet, which is then finally forwarded to the JSP servlet to generate HTML (or something else).
If you intend to incorporate business logic into JSPs, scriptlets are generally difficult to maintain ... although if you are just going to display an IP address, this should not be a concern. (The preferred approach from a technical point of view is to use tags and the JSP expression language.)
Finally, there is no guarantee that the IP address returned by getRemoteAddr() will be the actual IP address of the client. It can be a proxy address or even a complete manufacture.
Stephen c
source share