在FreeMarker上获取URL的queryString [英] get queryString of a URL on FreeMarker

查看:361
本文介绍了在FreeMarker上获取URL的queryString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处学习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&param2=123,您可以检索以下参数:

For query string ?param1=abc&param2=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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆