Get Users IP Address : Request « Servlet « Java Tutorial






import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Main extends HttpServlet {

  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    // Print out the IP address of the caller
    out.println(request.getRemoteAddr());

  }

}








25.12.Request
25.12.1.Print Request Headers for a Servlet
25.12.2.Get Servlet Request Parameter
25.12.3.Get Remote User and display welcome message
25.12.4.Get Users IP Address
25.12.5.Get Remote Host from Servlet Request
25.12.6.Request parsing and encoding utility methods