The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.servlet  [11 examples] > Requests  [6 examples]

e1045. Getting the Client's Address in a Servlet

    // See also e1035 The Quintessential 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 Examples
e1040. Getting a Request Parameter in a Servlet
e1041. Preventing Concurrent Requests to a Servlet
e1042. Getting the Requesting URL in a Servlet
e1043. Getting a Request Header in a Servlet
e1044. Processing a HEAD Request in a Servlet


© 2002 Addison-Wesley.