如何通过客户端Java代码获取Google Web Toolkit中的当前URL? [英] How can I get the current URL in Google Web Toolkit via client side Java code?

查看:179
本文介绍了如何通过客户端Java代码获取Google Web Toolkit中的当前URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试阅读URL 在客户端Java代码中,但我无法弄清楚如何在Java中找到当前的URL。



当我尝试使用 httpServletRequest 按照这个问题,它表示它无法解析,并且不提供添加导入语句。



我正在使用Google使用Google App Engine的Web Toolkit。

解决方案

请看 Window.Location

  public static class Window.Location 




这个课程提供acces s到浏览器的位置的对象。位置对象包含有关当前网址的 信息以及操纵它的方法 。位置是一个非常简单的包装,所以不是所有浏览器的怪癖都隐藏在用户面前。


有许多方法可以检索信息( getHref())或获取构成组件(例如 getProtocol() getHost() getHostName()等)。

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

  static java。 lang.String getQueryString()
获取URL的查询字符串。

static java.lang.String getParameter(java.lang.String name)
获取指定名称的URL参数

static java.util.Map< java.lang.String中,java.util.List的< java.lang.String中>> getParameterMap()
返回主机页面的URL查询参数的映射;因为改变地图不会改变窗口的位置,返回的地图是不可变的。


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.

解决方案

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.

这篇关于如何通过客户端Java代码获取Google Web Toolkit中的当前URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆