Java: String representation of just the host, scheme, possibly port from servlet request

后端 未结 5 1788
天命终不由人
天命终不由人 2021-01-04 22:08

I work with different servers and configurations. What is the best java code approach for getting the scheme://host:[port if it is not port 80].

Here is some code I

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 22:43

    URI u=new URI("http://www.google.com/");
    String s=u.getScheme()+"://"+u.getHost()+":"+u.getPort();
    

    As Cookie said, from java.net.URI (docs).

提交回复
热议问题