如何通过客户端Java代码获取Google Web Toolkit中的当前URL?

Sen*_*ful 12 java url gwt httpwebrequest

我正在尝试在客户端Java代码中读取URL的查询参数,但我无法弄清楚如何在Java中查找当前URL.

当我尝试httpServletRequest按照此问题中的建议使用时,它表示无法解决它并且它不提供添加import语句.

我正在使用Google Web Toolkit和Google App Engine.

Ber*_*t F 21

看看Window.Location:

public static class Window.Location
Run Code Online (Sandbox Code Playgroud)

此类提供对浏览器位置对象的访问.location对象包含有关当前URL的信息以及操作它的方法.位置是一个非常简单的包装器,因此并非所有浏览器怪癖都对用户隐藏.

有许多方法来检索有关的URL信息,其中包括让整个事情(getHref())或获得的组成部件(例如getProtocol(),getHost(),getHostName()等).

既然你说你想要读取查询参数,你可能想要其中一个:

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.
Run Code Online (Sandbox Code Playgroud)

  • Window.Location.getHref()获取整个URL,而不仅仅是查询字符串. (2认同)