Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A good library to do URL Query String manipulation in Java [closed]

Tags:

java

url

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"); 

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

Thanks for your help !

like image 946
Guillaume Avatar asked Oct 20 '08 14:10

Guillaume


People also ask

What is URL query string?

A query string is the portion of a URL where data is passed to a web application and/or back-end database. The reason we need query strings is that the HTTP protocol is stateless by design. For a website to be anything more than a brochure, you need to maintain state (store data).

What is query string manipulation?

Essentially, query string manipulation is as simple as adding alphanumeric characters to a string. It's one of the simplest, most straightforward and most effective types of database hacking around.

What is URL string parser?

URL Parser provides a quick way to break down URLs into its individual components revealing the scheme, protocol, username, password, hostname, port, domain, subdomain, tld—or top-level domain—path and query string.


1 Answers

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

like image 107
Vinko Vrsalovic Avatar answered Oct 09 '22 06:10

Vinko Vrsalovic