guess what, the request in a JSP is nothing more or less than an HttpServletRequest.
You will have the same available in a
servlet.
Servlets and JSPs ARE Java in case you didn't know.
Of course outside the context of servlets and JSPs living in a servlet/JSP container you won't have any of that.
The code you mention will more likely give you your own ip address, how in heck do you expect it to return the remote address you're talking to if you ask for the local address???
If you're building your own socket communication, Socket has methods to return the ip address and/or hostname of the remote machine.
Socket is of course a lowlevel connection that knows no highlevel protocols so you'll have to glean the request parameters from the inputstream yourself by parsing the request.