0

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

2
  • Missing complete code Commented Oct 4, 2017 at 7:16
  • Maybe you are doing a POST (like in a form) or you URL encoded the entire URL so ? is actually %3F (sometimes shown URL decoded in some browsers). Commented Oct 4, 2017 at 7:25

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer , but this did not work for me.
Very odd... What output did you get? Which Java version do you have?
1

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.