get queryString of a URL on FreeMarker

后端 未结 3 1061
借酒劲吻你
借酒劲吻你 2020-12-19 01:40

learning FTL here.

I\'m trying to get add a query string on my FTL page, like http://localhost/search, i\'d like to add a query string on the URL, say <

相关标签:
3条回答
  • 2020-12-19 02:01

    I figured out 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.

    0 讨论(0)
  • 2020-12-19 02:06

    I tried to check request parameters with first post's code:

    <#if RequestParameters.bing??>
    

    BUT nothing happened. Then I checked <#if RequestParameters.param1??> then I got result.

    I hope it helps someone.

    0 讨论(0)
  • 2020-12-19 02:17

    For query string ?param1=abc&param2=123, you can retrive params like below:

    ${RequestParameters.param1} & ${RequestParameters.param2}

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

    parameters are something that followed by < protocol >://< host >:< port >?< param1 >&< param2 >&..

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

    0 讨论(0)
提交回复
热议问题