Parsing a URL in Java

前端 未结 4 1943
我寻月下人不归
我寻月下人不归 2021-01-20 16:32

I am looking for an equivalent to PHP\'s \"parse_url\" function in Java. I am not running in Tomcat. I have query strings saved in a database that I\'m trying to b

4条回答
  •  感情败类
    2021-01-20 16:35

    You can accomplish that using java.net.URL:

    URL url = new URL("http://hostname:port/path?arg=value#anchor");
    String protocol = url.getProtocol(); // http
    String host = url.getHost(); // hostname
    String path = url.getPath(); // /path
    int port = url.getPort(); // port
    String query = url.getQuery(); // arg=value
    String ref = url.getRef(); // anchor
    

提交回复
热议问题