Return the current URL query parameters as a map.

For instance: ?key1=foo&key2=bar&key2=fizz in the URL will return {"key1": ["foo"], "key2": ["bar", "fizz"]}

Method Signatures and Parameters

Jt.urlQueryParameters()

Returns after .use()

(Map<String, List<String>>)

The current Map<String, List<String>> value of the component.

Examples

Using query parameters for app configuration

import java.util.List;

import io.javelit.core.Jt;

public class QueryParamsApp {
  public static void main(String[] args) {
    var params = Jt.urlQueryParameters();

    String name = params.getOrDefault("name", List.of("unknown user")).get(0);

    Jt.title("Query params reader").use();
    Jt.text("Hello " + name).use();
    // URL: ?name=Alice would show:
    // Hello Alice
  }
}

forum

Still have questions?

Go to our discussions forum for helpful information and advice from Javelit experts.