2015-02-22 19:34

[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

  1. URL base1 = new URL("http://localhost:8090/home/"); 
  2.  
  3. System.out.println(new URL(base1,"Service.json")); 
  4. // http://localhost:8090/home/Service.json 
  5.  
  6. System.out.println(new URL(base1,"/Service.json")); 
  7. // http://localhost:8090/Service.json 
  8.  
  9. System.out.println(new URL(base1,"./Service.json")); 
  10. // http://localhost:8090/home/Service.json 
  11.  
  12.  
  13. URL base2 = new URL("http://localhost:8090/home/index"); 
  14.  
  15. System.out.println(new URL(base2,"Service.json")); 
  16. // http://localhost:8090/home/Service.json 
  17.  
  18. System.out.println(new URL(base2,"/Service.json")); 
  19. // http://localhost:8090/Service.json 
  20.  
  21. System.out.println(new URL(base2,"./Service.json")); 
  22. // http://localhost:8090/home/Service.json 

0 回應: