在 GWT 中创建 URL 参数
我在此处提出了一个相关问题
如何使用 GWT 以编程方式将参数写入 URL? 我从之前的问题中了解到,参数需要位于锚点之前,但是如何从 GWT 中做到这一点?
这是不起作用的代码:
Hyperlink pg1 = new Hyperlink("Test", "?testing=abc#pg1");
它会产生以下 url:
http://localhost:8080/Athena.html#?testing=abc%23pg1
我正在考虑使用 Window.Location.assign(),但 javadoc 说这会丢失我的应用程序的状态。
I asked a related question here
How do I programatically write parameters into the URL using GWT? I've learned from my previous question that parameters need to go before the anchor, but how do I do that from GWT?
Here's the code that doesn't work:
Hyperlink pg1 = new Hyperlink("Test", "?testing=abc#pg1");
It results in the following url:
http://localhost:8080/Athena.html#?testing=abc%23pg1
I was thinking about using Window.Location.assign(), but the javadoc says that will loose the state of my application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对象 HyperLink 似乎是用于链接到内部状态的,并且可能是这样编写的,因此更改其 href 很困难?
我建议您使用此类 http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/InlineHTML.html - 显然你正在生成href 编程方式,因此应该很容易生成提供给 InlineHTML 对象的元素。
The object HyperLink seems to be for linking to internal states, and probably was written so that changing its href is difficult?
I suggest you use this class http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/InlineHTML.html instead - obviously you are generating the href programatically, so it should be easy to generate the element to supply to the InlineHTML object.
您正在使用 此构造函数,它接收历史记录标记作为第二个构造函数参数,因此您将得到上述结果。
使用
setHTML()
方法 在链接上设置正确的值。You are using this constructor which receives a history token as the second constructor argument, hence you are getting said result.
Use the
setHTML()
method to set the correct value on the link.