mskm
mskm

Reputation: 37

getQueryString returns empty string when queryParameter has no value

I have URL like http://example.com/foo/?locale=en_US&xyz, when i do a getQueryString() on the URL i get back an empty String

I am doing "request.getQueryString()" on the URL

Upvotes: 0

Views: 1774

Answers (2)

Tnadev
Tnadev

Reputation: 10112

Doc says

Returns: a String containing the query string or null if the URL contains no query string. The value is not decoded by the container.

The value is not decoded by the container.

String queryString = URLDecoder.decode(request.getQueryString(), "UTF-8");

This will make getQueryString() work.

Recommend to get params using getParameter()

Upvotes: 1

user8654079
user8654079

Reputation:

getQuery() works for me:

     String str = "http://example.com/foo/?locale=en_US&xyz";
     URL url = new URL(str);
     System.out.println(url.getQuery());

Output: locale=en_US&xyz

Upvotes: 1

Related Questions