Standard Java Class for common URL/URI manipulation

后端 未结 3 1390
一生所求
一生所求 2021-02-05 11:12

This question has almost certainly been asked before, but I ask it anyway because I couldn\'t find an answer.

Generally, is there a utility class of some sort that assis

相关标签:
3条回答
  • 2021-02-05 11:26

    I personnaly like UriBuilder from jax-rs

    0 讨论(0)
  • 2021-02-05 11:32

    There isn't really (oddly enough) any standard that does it all. There are some bits and pieces, usually buried in various util packages:

    I've used http://java.net/projects/urlencodedquerystring/pages/Home to decent effect (for extraction of parameters).

    Atlassian's JIRA has http://docs.atlassian.com/jira/4.2/index.html?com/atlassian/jira/util/UrlBuilder.html, which I've actually extracted from the jar and used.

    On Android, http://developer.android.com/reference/android/net/Uri.Builder.html is a Uri builder that works pretty well as far as building a url with ease.

    And finally, in a classic case of history repeating itself: A good library to do URL Query String manipulation in Java.

    I'd really just rip out the android.net.Uri.Builder class and pair that with the urlencodedquerystring class and then carry those around with you, but this does seem like a good candidate for an Apache commons package.

    0 讨论(0)
  • 2021-02-05 11:32

    This does not answer OP's question directly (i.e. it's not a generic, all-around library for URL manipulation), but: if you're going to be using Spring anyway, you might as well consider the ServletUriComponentsBuilder and UriComponentsBuilder classes (see here and here for javadocs).

    I believe they are bundled with the spring-web dependency. IMHO, these offer quite a few convenient utility methods for working with URIs, URLs and query parameters.

    0 讨论(0)
提交回复
热议问题