Grails URL Mapping and slash character in URL

2019-05-11 12:34发布

I'm facing the following problem:

My Grails (2.2.0) app has the following URL Mapping:

"/api/clientQuote/$labcode/$cliCode/$quoCode"(controller: "clientQuote") {
  action = [GET: "get"]
}

Let's suppose the following values:

$labcode = BRMIN
$cliCode = CL-000236
$quoCode = QT-000965/0-0

Since $quoCode has a slash character, it's necessary to replace it for %2F. This way, a possible URL could be:

http://myapp.com:9090/CCLASService/api/clientQuote/BRMIN/CL-000236/QT-000965%2F0-0

When I put this URL in any browser a blank screen is showed as return. It's strange because the request doesn't even reach my Grails controller.

For other side, if I change the url for:

http://myapp.com:9090/CCLASService/clientQuote/get?labcode=BRMIN&cliCode=CL-000236&quoCode=QT-000965%2F1-0

Everything works fine, I receive a correct XML response to my request.

The question is: Why when I use a specific URL Mapping with a encoded character I receive a blank screen as return?

标签: url grails
1条回答
Root(大扎)
2楼-- · 2019-05-11 13:01

URL mappings can use $paramName** to allow slashes within a particular parameter - this is typically used with something like a CMS where you want to map a whole virtual path hierarchy to a single controller, but it could be useful in your case too.

"/api/clientQuote/$labcode/$cliCode/$quoCode**"(controller: "clientQuote") {
  action = [GET: "get"]
}

This would permit http://myapp.com:9090/CCLASService/api/clientQuote/BRMIN/CL-000236/QT-000965/0-0 even without the slash escaped.

查看更多
登录 后发表回答