Creating custom URI scheme using URI class

你说的曾经没有我的故事 提交于 2020-01-21 09:41:13

问题


I need to create a custom URI scheme for my project. i.e

urn:myprotocol:{p1}:{p2}:{p3}:{p4} - opaque representation

myprotocol://{p1}/{p2}/{p3}/{p4} - hierarchical representation.

How can I add my scheme to Java URI class? Or, how can I make Java URI to understand my scheme, so I could use it in my code?

Concrete examples are welcome.

Thanks.


回答1:


Are you sure you need to create a new URI scheme?

It's considered bad practice to create implementation-specific schemes.

See:

  • http://infomesh.net/2001/09/urischemes
  • http://www.w3.org/TR/webarch/#URI-scheme
  • http://tools.ietf.org/search/rfc4395



回答2:


The Java API has a pretty good explanation of how to do that: http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html

Without knowing what you are trying to do, I would use this constructor of URI: URI(String scheme, String authority, String path, String query, String fragment)



来源:https://stackoverflow.com/questions/2537255/creating-custom-uri-scheme-using-uri-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!