java获取URI的路径部分和查询部分

可以通过URI的getPath()函数获取路径部分,通过getQuery()函数获取查询部分。

举例:

package com.thb;

import java.net.URI;
import java.net.URISyntaxException;

public class Demo3 {

    public static void main(String[] args) throws URISyntaxException {
        String address = "http://localhost:8080/restful/result/?name=thb";
        URI servicePoint = new URI(address);
        String path = servicePoint.getPath();
        String query = servicePoint.getQuery();
        System.out.println("path: " + path);
        System.out.println("query: " + query);
    }
}

运行输出:

path: /restful/result/
query: name=thb

你可能感兴趣的:(java,开发语言)