Getting the Client's Address in a Servlet - Java Servlet JSP

Java examples for Servlet JSP:Servlet

Description

Getting the Client's Address in a Servlet

// 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 Tutorials