在 GWT Activitie 的位置令牌的令牌中对名称/值对进行编码的建议方法
在使用 History/Activities/Places api 的 GWT 中,您最终会得到如下 URL
http://192.168.0.104:8888/brokerage.html?gwt.codesvr=192.168.0.104:9997#StartPlace:params
其中单词 params 是将“令牌”放置在可以将参数传递到 StartPlace 对象中的位置。对于我的大多数应用程序,单个字符串足以通过按下刷新来重新加载我的数据。然而,在一些活动/地点/页面上,我需要将该地点令牌拆分为多个名称/值对。
有人对如何处理这个问题有建议吗?我目前正在编写一个类,该类通过使用 &name=value 以 url 方式分隔名称/值对来构建字符串。如果有人知道一个可以处理这个或其他事情的类,那就太好了。
In GWT using the History/Activities/Places apis you end up with urls like this
http://192.168.0.104:8888/brokerage.html?gwt.codesvr=192.168.0.104:9997#StartPlace:params
Where the word params is the place "token" where parameters can be passed into the StartPlace object. For most of my applications a single string is enough to reload my data with refreshed is pressed. On a few Activities/Places/Pages however I need to split that Place token into a number of name/value pairs.
Does anybody have a suggestion for how to handle this? I am currently writing a class that builds a string out of name/value pairs by separating them in a url fashion using &name=value. It would be great if somebody knew of a class that could handle this or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如何简单地从
Window.Location
复制/粘贴代码进行解析(私有方法buildListParamMap
;您也可以使用 JSNI 来调用它——它允许绕过 Java 可见性——假设它是一个静态方法,没有状态),以及用于序列化的UrlBuilder.buildString
?How about simply copy/pasting the code from
Window.Location
for the parsing (private methodbuildListParamMap
; you can also call it using JSNI –which allows bypassing Java visibility– given that it's a static method with no state), andUrlBuilder.buildString
for the serialization?....
这都是未经测试的代码,并且它具有未经检查的数组边界!确保没有多余的“&”或“=”符号,因为它们会搞乱解析。
....
This is all untested code, and it has unchecked array bounds! Make sure you don't have extraneous '&' or '=' signs, since they'll mess up the parsing.
这是我想出的,它应该对其他人有用。使用哈希映射是一个好主意,我将修改我的代码。
和
This is what I came up with, it should work for others. Using a hash map is a good idea, I'll modify my code.
And