Get Query String Parameters

Single value

The example below gets a value from the query string i.e.

If you set the value of category to "" as on line 1 you can then perform your logic around this - see code line 4. You can also use .equals(), .contains() or .isSet() as explained on this page.

  1. #set ($category ="")  
  2. #set ($category = $request.getParameter("category"))  
  4. #if($category == "")  
  5. A category has not been selected  
  6. #else  
  7.   ##This will output apples  
  8.     The category you are looking at is: $category  
  9. #end  

Multiple values

You may also wish to get a parameter from a multiple select box, in the example regions.

Works for query string like this:

  1. #set ($regions = $request.getParameterValues('regions'))  
comments powered by Disqus