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

编程入门 行业动态 更新时间:2024-10-24 08:28:39
本文介绍了如何通过客户端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?

本文发布于:2023-11-16 04:32:09,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   代码   Java   Google   Toolkit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!