url和uri区别
作者:互联网
这两天在写代码的时候,由于涉及到资源的位置,因此,需要在Java Bean中定义一些字段,用来表示资源的位置,比如:imgUrl,logoUri等等。但是,每次定义的时候,心里都很纠结,是该用imgUrl还是imgUri呢?
同样的,另外一个问题:String HttpServletRequest.getRequestURI();和StringBuffer HttpServletRequest.getRequestURL();返回的内容有何不同?为什么会如此?
带着这些问题到网上去搜了下,没发现让自己看了明白的解释,于是,想到了Java类库里有两个对应的类java.net.URI和java.net.URL,终于,在这两个类里的javadoc里找到了答案。
URIs, URLs, and URNs
首先,URI,是uniform resource identifier,统一资源标识符,用来唯一的标识一个资源。而URL是uniform resource locator,统一资源定位器,它是一种具体的URI,即URL可以用来标识一个资源,而且还指明了如何locate这个资源。而URN,uniform resource name,统一资源命名,是通过名字来标识资源,比如mailto:java-net@java.sun.com。也就是说,URI是以一种抽象的,高层次概念定义统一资源标识,而URL和URN则是具体的资源标识的方式。URL和URN都是一种URI。
在Java的URI中,一个URI实例可以代表绝对的,也可以是相对的,只要它符合URI的语法规则。而URL类则不仅符合语义,还包含了定位该资源的信息,因此它不能是相对的,schema必须被指定。
U2FsdGVkX1/vKPjyUw96CusmumtRXiSJd6YsbmvZmXTfuQbggapAS6d7I/PfUxMp
80V6lS2sZdsmoBqyoacPMdf+9pJs+8Lch0OLeJOMNlEdHra/TiY+wPDqyUTtgf1G
zPBDmvHhOutvr8eA23PdhegzXthXMOhTzOpxu1U0z/1KQ8E8JdaMDkMiT5Lj9knr
IQPPfVQNWEUwvjy9k+rnMzXNjsoGjIddGMsUvvXC/rTk24Tu3HWkJW2EL2kueu6y
1RISANmuNsCmTspHFF5yO5IpwTTRWJjq8zNhwjbkQTivxyfoBt8AgJDj9dh86uTj
7CyOyArbc6V9QOK+AY4fPbFWms6oNAnnFlSTxKBaGeRa5TGMD732ZnM9SEB3f+N2
2gLYl165qdOXOYm6Zp4lBchdyd1gMiLVh2XnUBUjVz2grkwo5QABw8i4xppi8PPz
E8T2CtTm9su/8aO30nccui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