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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值