Java中Request获取ip,port等信息

public class RequestDemo1 extends HttpServlet {
//request 获取IP地址
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
   String uri = request.getRequestURI();//返回请求行中的资源名称
   String url = request.getRequestURL().toString();//获得客户端发送请求的完整url
   String ip = request.getRemoteAddr();//返回发出请求的IP地址
   String params = request.getQueryString();//返回请求行中的参数部分
   String host=request.getRemoteHost();//返回发出请求的客户机的主机名
   int port =request.getRemotePort();//返回发出请求的客户机的端口号
   System.out.println(ip);
   System.out.println(url);
   System.out.println(uri);
   System.out.println(params);
   System.out.println(host);
   System.out.println(port);
}

你可能感兴趣的:(request)