URI类的基本使用

代码说明问题

对这个path和rawPath分的不是太清楚,就记下了。

System.out.println("path=" + uri.getPath());

System.out.println("rawPath=" + uri.getRawPath());

@Test
public void test1() throws URISyntaxException {
    String target = "http://www.baidu.com/s?wd=hello&rsv_bp=0&tn=baidu&rsv_spt=3&ie=utf-8&rsv_sug3=3&rsv_sug4=622&rsv_sug1=3&rsv_sug2=0&inputT=1010";
    URI uri = new URI(target);
    System.out.println("path=" + uri.getPath());
    System.out.println("rawPath=" + uri.getRawPath());
    System.out.println("port=" + uri.getPort());
    System.out.println("host=" + uri.getHost());
    System.out.println("queryString=" + uri.getQuery());
    System.out.println("rawQueryString=" + uri.getRawQuery());
    System.out.println("scheme=" + uri.getScheme());
}

运行结果:

path=/s

rawPath=/s

port=-1

host=www.baidu.com

queryString=wd=hello&rsv_bp=0&tn=baidu&rsv_spt=3&ie=utf-8&rsv_sug3=3&rsv_sug4=622&rsv_sug1=3&rsv_sug2=0&inputT=1010

rawQueryString=wd=hello&rsv_bp=0&tn=baidu&rsv_spt=3&ie=utf-8&rsv_sug3=3&rsv_sug4=622&rsv_sug1=3&rsv_sug2=0&inputT=1010

scheme=http


Process finished with exit code 0


在这里,path和rawPath打印出的结果是一样的。所以暂时认为没有区别。(可能有区别,因为名字不一样嘛。。)


看说明文档是这么说的:

/**
 * Returns the decoded path component of this URI.
 *
 * <p> The string returned by this method is equal to that returned by the
 * {@link #getRawPath() getRawPath} method except that all sequences of
 * escaped octets are <a href="#decode">decoded</a>.  </p>
 *
 * @return  The decoded path component of this URI,
 *          or {@code null} if the path is undefined
 */
public String getPath() {
    if ((decodedPath == null) && (path != null))
        decodedPath = decode(path);
    return decodedPath;
}

/**
 * Returns the raw path component of this URI.
 *
 * <p> The path component of a URI, if defined, only contains the slash
 * character ({@code '/'}), the commercial-at character ({@code '@'}),
 * and characters in the <i>unreserved</i>, <i>punct</i>, <i>escaped</i>,
 * and <i>other</i> categories. </p>
 *
 * @return  The path component of this URI,
 *          or {@code null} if the path is undefined
 */
public String getRawPath() {
    return path;
}

===================END===================

你可能感兴趣的:(URI类的基本使用)