Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Java method that encodes a collection of parameters as a URL query component?

Tags:

People also ask

How do I encode a URL query in Java?

A URL String or form parameters can be encoded using the URLEncoder class – static encode (String s, String enc) method. For example, when a user enters following special characters, and your web application doesn't handle encoding, it will caused cross site script attack.

What is URL encoder in Java?

public class URLEncoder extends Object. Utility class for HTML form encoding. This class contains static methods for converting a String to the application/x-www-form-urlencoded MIME format. For more information about HTML form encoding, consult the HTML specification.

How do you query parameters in a URL?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.

Should I encode URL parameters?

Why do we need to encode? URLs can only have certain characters from the standard 128 character ASCII set. Reserved characters that do not belong to this set must be encoded. This means that we need to encode these characters when passing into a URL.


Is there a widely-used Java library that does something like what dojo.objectToQuery() does? E.g. (assuming the use of HttpCore's HttpParams object, but any key-value mapping will do):

HttpParams params = new BasicHttpParams()
    .setParameter("foo", "bar")
    .setParameter("thud", "grunt");
UnknownLibrary.toQueryString(params);

should yield "foo=bar&thud=grunt".

I know it's not hard to write but it seems like it should have already been written. I just can't find it.