在FreeMarker上获取URL的queryString [英] get queryString of a URL on FreeMarker
问题描述
在此处学习FTL.
我想在我的FTL页面上添加一个查询字符串,例如http://localhost/search
,我想在URL上添加一个查询字符串,例如http://localhost/search?bing
,以便用户可以在以下情况下使用默认设置进行切换没有查询字符串.
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 http://localhost/search?bing
so that user could switch with the default setting when there is no query string.
但是,我没有从URL上获取queryString的运气. 我还试图避免对此使用JavaScript解决方案.
However, I have no luck on grabbing the queryString from the URL. I'm also trying to avoid using a JavaScript solution on this.
这是我的代码:
<#if RequestParameters.bing?exists >
<#assign useServer = "http://www.bing.com">
<#else>
<#assign useServer = "http://www.google.com">
</#if>
<h1>${useServer}</h1>
在查询字符串中键入
进入url仍在h1
上返回http://www.google.com
.
typing in the queryString into the url still returns http://www.google.com
on the h1
.
推荐答案
对于查询字符串?param1=abc¶m2=123
,您可以检索以下参数:
For query string ?param1=abc¶m2=123
, you can retrive params like below:
${RequestParameters.param1
}& ${RequestParameters.param2}
还要尝试<#if RequestParameters.bing??>
参数是紧随其后的 <协议>://<主机>:<端口> ?< param1>&< param2> ..
parameters are something that followed by < protocol >://< host >:< port >?< param1 >&< param2 >&..
例如 https://www.google.co.in/search?q=StackOverflow URL参数名称为 q ,值为'StackOverflow'
for example in https://www.google.co.in/search?q=StackOverflow URL param name is q and value is 'StackOverflow'
这篇关于在FreeMarker上获取URL的queryString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!