|
How to get the client address in a Servlet |
|
|
This Java tip illustrates a method of getting the client's address in a Servlet.
In an embodiment developer may use this tip in their client server applications
for knowing at the server end the address of the client which made the request.
// This method is called by the servlet container to process a GET request.
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
// Get client's IP address
String addr = req.getRemoteAddr(); // 123.123.123.123
// Get client's hostname
String host = req.getRemoteHost(); // hostname.com
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.