Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the current URL in Google Web Toolkit via client side Java code?

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.

like image 844
Senseful Avatar asked Dec 23 '10 00:12

Senseful


1 Answers

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.
like image 190
Bert F Avatar answered Sep 27 '22 20:09

Bert F