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

后端 未结 1 1989
臣服心动
臣服心动 2021-02-19 19:35

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 httpSe

1条回答
  •  孤独总比滥情好
    2021-02-19 19:45

    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> 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.
    

    0 讨论(0)
提交回复
热议问题