如何通过客户端 Java 代码获取 Google Web Toolkit 中的当前 URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4515052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I get the current URL in Google Web Toolkit via client side Java code?
提问by Senseful
I'm trying to read the query arguments of the URLin client side Java code, but I can't figure out how to find the current URL in Java.
我试图在客户端 Java 代码中读取 URL 的查询参数,但我不知道如何在 Java 中找到当前的 URL。
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.
当我尝试httpServletRequest
按照此问题中的建议使用时,它说无法解决并且不提供添加导入语句。
I'm using Google Web Toolkit with Google App Engine.
我将 Google Web Toolkit 与 Google App Engine 一起使用。
回答by Bert F
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.
此类提供对浏览器位置对象的访问。location 对象包含有关当前 URL 和操作它的方法的信息。位置是一个非常简单的包装器,因此并非所有浏览器怪癖都对用户隐藏。
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).
有许多方法来检索有关的URL信息,其中包括让整个事情(getHref()
)或获得的组成部件(例如getProtocol()
,getHost()
,getHostName()
等)。
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.