I'm trying to read the query arguments of the URL in client side Java code, but I can't figure out how to find the current URL in Java.
When I tried using httpServletRequest
as recommended in this question, it says that it cannot be resolved and it doesn't offer adding an import statement.
I'm using Google Web Toolkit with Google App Engine.
Look at Window.Location:
public static class Window.Location
This class provides access to the browser's location's object. The location object contains information about the current URL and methods to manipulate it. Location is a very simple wrapper, so not all browser quirks are hidden from the user.
There are a number of methods to retrieve info about the URL, including one to get the whole thing (getHref()
) or get the constituent components (e.g. getProtocol()
, getHost()
, getHostName()
, etc).
Since you say you want to read the query arguments, you probably want one of these:
static java.lang.String getQueryString()
Gets the URL's query string.
static java.lang.String getParameter(java.lang.String name)
Gets the URL's parameter of the specified name
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> getParameterMap()
Returns a Map of the URL query parameters for the host page; since changing the map would not change the window's location, the map returned is immutable.