我正在尝试 read the query arguments of the URL在客户端 Java 代码中,但我不知道如何在 Java 中找到当前 URL。
当我按照 this question 中的建议尝试使用 httpServletRequest
时,它说它无法解决并且不提供添加导入语句。
我将 Google Web Toolkit 与 Google App Engine 结合使用。
最佳答案
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.
有许多方法可以检索有关 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.
关于java - 如何通过客户端 Java 代码获取 Google Web Toolkit 中的当前 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4515052/