2015-02-22

[Java] URL 筆記

Request URL
http://user:passwd@30thh.loc:8480/test%3F+b;?p+1=c+d&p+2=e+f#ref

MethodResult
getAuthority()user:passwd@30thh.loc:8480
getDefaultPort()80
getFile()/test%3F+b;?p+1=c+d&p+2=e+f
getHost()30thh.loc
getPath()/test%3F+b;
getPort()8480
getProtocol()http
getQuery()p+1=c+d&p+2=e+f
getRef()ref
getUserInfo()user:passwd
toString()http://user:passwd@30thh.loc:8480/test%3F+b;?p+1=c+d&p+2=e+f#ref

URL base1 = new URL("http://localhost:8090/home/");

System.out.println(new URL(base1,"Service.json"));
// http://localhost:8090/home/Service.json

System.out.println(new URL(base1,"/Service.json"));
// http://localhost:8090/Service.json

System.out.println(new URL(base1,"./Service.json"));
// http://localhost:8090/home/Service.json


URL base2 = new URL("http://localhost:8090/home/index");

System.out.println(new URL(base2,"Service.json"));
// http://localhost:8090/home/Service.json

System.out.println(new URL(base2,"/Service.json"));
// http://localhost:8090/Service.json

System.out.println(new URL(base2,"./Service.json"));
// http://localhost:8090/home/Service.json

沒有留言:

張貼留言

你好!歡迎你在我的 Blog 上留下你寶貴的意見。