4

My grails controller gets invoked by the following URLs

/center/madrid/12-de-octubre
/center/madrid/12-de-octubre?opt=1

I need the controller to behave differently if there are any parameters after the ? in the URL

I have the following URL mapping:

   name center: "/center/$_uni_city/$_uni_facility_name" {
        controller = "site"
        action = "centerprofile"
} 

While I can find all parameters (e.g. _uni_city=Madrid, opt=1) I am unable to determine which parameters come from the querystring after applying URLMappings (i.e. opt in the example above).

Is there a way to retrieve the original request URL (i.e.
/center/madrid/12-de-octubre?opt=1) in the grails controller?

user3028981
  • 91
  • 1
  • 5

2 Answers2

5

To get the original parameters in the request URL use:

request.queryString 
user3028981
  • 91
  • 1
  • 5
  • Thanks. This property is not even mentioned on the Grails doc, this is lame. – Ser Jun 03 '14 at 13:57
  • 3
    @Ser well, the docs do mention that `request` is an implementation of `HttpServletRequest`, which `getQueryString()` is part of. http://docs.oracle.com/javaee/1.4/api/javax/servlet/http/HttpServletRequest.html – Charles Wood Feb 02 '16 at 19:17
5

See description of Grails request.

  • forwardURI - Useful for obtaining the current request URI since the request objects requestURI property returns the original URI, not the matched one.

Solution:

class URLController{
  def printCurrentUrl = {
   render request.forwardURI
  }
}
Tomáš
  • 2,078
  • 3
  • 22
  • 21