• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get request parameters in grails

 
Sabarish Venkat
Ranch Hand
Posts: 136
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually in jsp we will use request.getParameter() function to get the parameter values from prevoius page. Like that how we can get the value in grails do we have any functions to get a parameter value from gsp page to a controller.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Grails provides a wrapper around the HttpServletRequest and it is injected automatically into every controller with a variable named params. So if you had the following:

Once submitted, you would access username in your controller like so:
 
Sabarish Venkat
Ranch Hand
Posts: 136
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats fine but when i want to use that variable across my pages wherever i wish how i take the value i want to pass that params to the gsp or to the model class
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every view in Grails is accessed via a Controller. If you want to pass data from the controller to your GSP you would do something like the following:



That would, by convention, render a show.gsp and pass userInstance into the GSP. You should really spend some time in the documentation. It is quite verbose on this topic.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sabarish Venkat,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic