在 Java 中进行 URL 查询字符串操作的好库 [英] A good library to do URL Query String manipulation in Java

查看:17
本文介绍了在 Java 中进行 URL 查询字符串操作的好库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Java 中进行一些非常简单的 URL 操作.就像获取查询中参数的值,或更新它,......我期待在 commons-lang 包中找到一个简单的实用程序类,但没有.我知道这是一个简单的问题,但如果已经写了一些东西,为什么还要再写?你知道吗?

I need to do a few very simple URL manipulations in Java. Like get the value for a parameter in the query, or update it, ... I was expecting to find a simple utility class doing that in the commons-lang package, but no. I know it is a simple problem, but if there is something already written, why do it again ? Do you know of any ?

我希望至少具有以下功能:

I would like to have at least the following capabilities :

String myUrl = "http://www.example.com/test.html?toto=1&titi=2";

// get the value of a parameter
String parameterValue = UrlUtils.getParameterValue(myUrl, "toto");
Assert.equals(parameterValue, "1");

// update a parameter
String newUrl = UrlUtils.updateParameter(myUrl, "toto", 3);
parameterValue = UrlUtils.getParameterValue(myUrl, "toto");
Assert.equals(parameterValue, "3");

理想情况下,它将处理所有与编码相关的问题,并处理 java.net.Url 和字符串.

Ideally, it would take care of all encoding related issues, and work with java.net.Url as well as with Strings.

感谢您的帮助!

推荐答案

我认为你想要的是查询字符串解析器而不是 url 操作器,这里是一个:http://ostermiller.org/utils/CGIParser.java.html

I think what you want is called a query string parser instead of an url manipulator and here's one: http://ostermiller.org/utils/CGIParser.java.html

这篇关于在 Java 中进行 URL 查询字符串操作的好库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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