Sadik Sadik - 6 months ago 101
Java Question

How to get query string parameters in java play framework?

I'm very new to java play framework. I've set up all the normal routes like /something/:somthingValue and all the others. Now I want to create route the accepts query parameters like


Here I want to get all the params after "?" as key==>value pair.


You can wire in your query parameters into the routes file: in section "Parameters with default values"

Or you can ask for them in your Action:

public class Application extends Controller {

    public static Result index() {
        final Set<Map.Entry<String,String[]>> entries = request().queryString().entrySet();
        for (Map.Entry<String,String[]> entry : entries) {
            final String key = entry.getKey();
            final String value = Arrays.toString(entry.getValue());
            Logger.debug(key + " " + value);
        return ok(index.render("Your new application is ready."));

For example the http://localhost:9000/?a=1&b=2&c=3&c=4 prints on the console:

[debug] application - a [1]
[debug] application - b [2]
[debug] application - c [3, 4]
[debug] application - 1
[debug] application - 2
[debug] application - 3

Note that c is two times in the url.