转载自: http://hi.baidu.com/wy521ly/blog/item/861075d3e2f9e031970a169e.html
初始化一个url:
try {
url = new URL("http://www.geelink.cn");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
url的各种get方法:
System.out.println("getAuthority:"+url.getAuthority());
System.out.println("getQuery:"+url.getQuery());
System.out.println("getPath:"+url.getPath());
System.out.println("getProtocol:"+url.getProtocol());
System.out.println("getFile:"+url.getFile());
System.out.println("getHost:"+url.getHost());
System.out.println("getRef:"+url.getRef());
System.out.println("getPort:"+url.getPort());
当url为:http://www.geelink.cn/index.html时,各种方法的返回值为
getAuthority:www.geelink.cn
getQuery:null
getPath:/index.html
getProtocol:http
getFile:/index.html
getHost:www.geelink.cn
getRef:null
getPort:-1
当url为:http://www.geead.com/html/FAQ.html#paiqi时,各种方法的返值为:
getAuthority:www.geead.com
getQuery:null
getPath:/html/FAQ.html
getProtocol:http
getFile:/html/FAQ.html
getHost:www.geead.com
getRef:paiqi
getPort:-1
当url为:http://www.geead.com/index.php?option=com_user&view=reset时,各种方法的返回值为:
getAuthority:www.geead.com
getQuery:option=com_user&view=reset
getPath:/index.php
getProtocol:http
getFile:/index.php?option=com_user&view=reset
getHost:www.geead.com
getRef:null
getPort:-1
大家注意一下区别!另外getport如果没有特别设定的话默认返回-1!