如何转义 UrlMappings.groovy 中 Url 模式中的 # 符号?
为了维护项目中当前的 URL 集,我必须能够在 URL 中使用 #(井号)。由于某种原因,井号在 UrlMappings.groovy 项目中似乎无法正常工作。
在 UrlMappings.groovy 中放置 # 符号时是否必须使用特殊的转义序列?
我是否遗漏了一些根本不能使用井号的原因?
在以下 URL 映射示例中,浏览器转到正确的页面,但 pageName 变量为 null:
"/test/${urlName}#/overview"(controller:'test', action:'overview') {
pageName = "overview"
}
In order to maintain the current set of Urls in a project, I have to be able to use the # (pound sign) in the Url. For some reason the pound sign does not appear to work normally in this project for UrlMappings.groovy.
Is there a special escape-sequence that must be used when placing # signs in UrlMappings.groovy?
Am I missing some reason why one cannot use pound signs at all?
In the following URL Mapping example, the browser goes to the correct page, but the pageName variable is null:
"/test/${urlName}#/overview"(controller:'test', action:'overview') {
pageName = "overview"
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 url 中 # 之后的所有内容都会在浏览器的客户端进行处理,浏览器会尝试找到 a 并滚动到该位置。
如果你转储包含磅字符的请求,你是否能看到#后面的数据?
I thought everything after # in the url would be treated on the client side of the browsers where it tries to find a and scroll to that location.
If you dump the request containing the pound char, do you even see the data behind #?
我使用了命名 URL 映射,它工作正常,无需转义“#”符号:
编辑:我的上述答案是错误的。事实上,当主页是视图的默认操作时,它属于一种特殊情况。
Netbrain是对的,“#”后面的路径永远不会发送到服务器。相反,我发现可以使用“%23”而不是“#”。请查看此处。
例如,我们应该使用
/test%23/abc
作为 URL 映射(在客户端和服务器端),而不是/test#/abc
。I used a Named URL mapping and it works fine, no need to escape the "#" sign:
EDIT: My above answer is wrong. In fact, it falls to a special case when homepage is the default action of the view.
Netbrain is right, the path after "#" will never be sent to server. In stead, I found that it's possible using "%23" instead of "#". Please take a look at here.
For example, instead of
/test#/abc
we should use/test%23/abc
as URL mapping (both at client side & server side).