URL,URI,URN的区别
java中操作URI(可以对URLecoder进行解码,这一定要解码之后再调用方法,不解码可能会有问题)
public void uriTest() throws Exception{
URI uri = new URI("https://www.qiandu.com:8080/goods/index.html?username=dgh&passwd=123#j2se");
System.out.println("scheme:" + uri.getScheme());
System.out.println("SchemeSpecificPart:" + uri.getSchemeSpecificPart());
System.out.println("Authority: " + uri.getAuthority());
System.out.println("host: " + uri.getHost());
System.out.println("port: " + uri.getPort());
System.out.println("path: " + uri.getPath());
System.out.println("query: " + uri.getQuery());
System.out.println("fragment: " + uri.getFragment());
}
输出的结果是:
scheme : https
SchemeSpecificPart : (http:和#之间的内容)//www.qiandu.com:8080/goods/index.html?username=dgh&passwd=123
Authority : www.qiandu.com:8080
host : www.qiandu.com
port : 8080
path : /goods/index.html
query : username=dgh&passwd=123
fragment : j2se(特#后面的内容)
java中操作URL:
public static void main(String[] args) throws IOException, URISyntaxException {
URL url = new URL("https://www.qiandu.com:8080/goods/index.html?username=dgh&passwd=123#j2se");
System.out.println("URL: " + url.toString());
System.out.println("protocol: " + url.getProtocol());
System.out.println("authority: " + url.getAuthority());
System.out.println("file name: " + url.getFile());
System.out.println("host: " + url.getHost());
System.out.println("path: " + url.getPath());
System.out.println("port: " + url.getPort());
System.out.println("default port:" + url.getDefaultPort());
System.out.println("query: " + url.getQuery());
System.out.println("ref: " + url.getRef());
};
输出的结果是:
URL: https://www.qiandu.com:8080/goods/index.html?username=dgh&passwd=123#j2se
protocol: https
authority: www.qiandu.com:8080
file name: /goods/index.html?username=dgh&passwd=123
host: www.qiandu.com
path: /goods/index.html
port: 8080
default port:443
query: username=dgh&passwd=123
ref:j2se