Get queryString URLs on FreeMarker

FTL training is here.

I am trying to add a query string to my FTL page, for example http://localhost/search , I would like to add a query string to the url, say http://localhost/search?bing so that the user can switch with the default setting, when the query string is missing.

However, I cannot capture the queryString from the URL. I am also trying to avoid using a JavaScript solution on this.

here is my code:

 <#if RequestParameters.bing?exists > <#assign useServer = "http://www.bing.com"> <#else> <#assign useServer = "http://www.google.com"> </#if> <h1>${useServer}</h1> 

entering the query string in the url still returns http://www.google.com in h1 .

+6
source share
2 answers

In the query string ?param1=abc¶m2=123 you can get the parameters as shown below:

${RequestParameters.param1 } and ${RequestParameters.param2}

And also try <#if RequestParameters.bing??>

Options

is this followed by <protocol>: // <host>: <port> ? <param1> & param2> & ..

for example, in https://www.google.co.in/search?q=StackOverflow URL parameter name q , and the value is 'StackOverflow'

+11
source

I decided to use request.getParameter ("param")

 <#if (request.getParameter("param")?has_content && request.getParameter("param")?lower_case?matches("true"))> <#assign useServer = "http://bing.com"> <#else> <#assign useServer = "http://google.com"> 

Worked like a charm.

+4
source

All Articles