用于常见URL / URI操作的标准Java类 [英] Standard Java Class for common URL/URI manipulation

查看:76
本文介绍了用于常见URL / URI操作的标准Java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前几乎肯定已经提出了这个问题,但无论如何我都会问它,因为我找不到答案。

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

一般来说,有没有一个实用类有助于与URL / URI相关的常见字符串操作吗?

Generally, is there a utility class of some sort that assists in common String manipulations associated with URL/URIs?

我在想像Java SE的 URL 类,但可能更强一些。我正在寻找能让你做简单事情的东西,比如:

I'm thinking something like Java SE's URL Class, but maybe a little beefier. I'm looking for something that will let you do simple things, like:


  • 获取查询字符串参数列表

  • 添加
    查询字符串参数的addParameter方法,它将
    负责添加&,?和=
    必要时

  • 此外,编码
    参数值将是理想的......

让我知道,谢谢!

推荐答案

没有(奇怪的)任何标准都可以做到这一切。有一些点点滴滴,通常埋在各种 util 包中:

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

我用过 http://java.net/projects/urlencodedquerystring/pages/Home 改善效果(用于提取参数)。

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

Atlassian的JIRA http://docs.atlassian.com/jira/4.2/index.html?com/atlassian/jira/util/UrlBuilder.html ,我实际上是从jar中提取的和使用过。

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.

在Android上, http://developer.android.com/reference/android/net/Uri.Builder.html 是一个Uri构建器,在构建URL方面非常有效。

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.

最后,在经典的历史案例中重复:一个很好的库,用于在Java中执行URL查询字符串操作

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

我真的只是扯掉了android.net.Uri.Builder类并将它与urlencodedquerystring类配对,然后随身携带它们,但这看起来似乎就像一个Apache commons包的好候选者。

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.

这篇关于用于常见URL / URI操作的标准Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆