【问题标题】:How to get the request URI in Grails?如何在 Grails 中获取请求 URI?
【发布时间】:2011-12-06 21:09:45
【问题描述】:

我有一个带有以下 RESTful uri 的简单 Grails 应用程序...

http://localhost:8080/kennis-api/funds/test/700

我的 URIMappings 中的映射是

 "/funds/test/$fcode" (controller: "fundCache"){
    action = [GET: "show"]
 }

在我的控制器中,我需要提取请求 URI,在本例中为“/funds/test/700”,但调用 request.uri 或 request.getRequestUri 不起作用。我尝试使用 request.requestURL,但这给了我

http://localhost:8080/kennis-api/grails/fundCache/show.dispatch

是否有特殊的成员或函数可以从中获取请求 uri?

【问题讨论】:

  • 我明白了,不直观,但无论如何...'request.forwardURI'
  • 刚刚找到这个。完全不直观。 Grails 一定是在幕后耍花招。

标签: grails groovy httprequest


【解决方案1】:

很简单,您需要原始地址,与您的响应将被转发的地址相同,它只是存储在请求中,并且可以通过以下方式检索: .

String originalURI = request.forwardURI  
//Do this where request is available, ex: Controllers :)
// Everywhere else you can use RequestContextHolder

.
.
希望有帮助 问候 库沙尔

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-08
    • 2019-01-26
    • 2011-09-14
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多