How does one escape the # sign in a Url pattern in UrlMappings.groovy?

荒凉一梦 提交于 2019-12-24 10:13:20

问题


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"
}

回答1:


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 #?




回答2:


I used a Named URL mapping and it works fine, no need to escape the "#" sign:

name test: "/#abc" (controller: 'test', action:'homepage')

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).



来源:https://stackoverflow.com/questions/5800103/how-does-one-escape-the-sign-in-a-url-pattern-in-urlmappings-groovy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!