HttpServletRequest.getLocalAddr(),得到的ip是0.0.0.0  是怎么回事呀?

解决方案 »

  1.   

    public String getUrl() {
    HttpServletRequest req = FlexContext.getHttpRequest();
    String serverIp = req.getLocalAddr();
    int serverPort = req.getLocalPort();
    String webAppName = FlexContext.getHttpRequest().getContextPath();
    StringBuffer bufPath = new StringBuffer();
    // bufPath.append("http://");
    // bufPath.append(serverIp);
    String urlIp = req.getRequestURL().toString();
    int weiz = urlIp.lastIndexOf(":");
    urlIp = urlIp.substring(0, weiz);
    bufPath.append(urlIp);
    if (serverPort != 80)
    bufPath.append(":" + serverPort);
    bufPath.append(webAppName);
    return bufPath.toString();
    }
      

  2.   

    InetAddress address = InetAddress.getLocalHost();
    address.getHostAddress();
    试试
      

  3.   

    系统host文件设置localhost为127.0.0.1就好了
      

  4.   

    你换这个方法:request.getRemoteAddr();试试。