一个很好的库,用于在Java中执行URL查询字符串操作 [英] A good library to do URL Query String manipulation in Java

查看:122
本文介绍了一个很好的库,用于在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作为和Strings一样。

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天全站免登陆