Velocity (VM) template request parameters: Getting GET variables

此生再无相见时 提交于 2019-12-06 16:14:27

Another option would be to use $httpUtil, a Liferay utility class that's injected in Velocity templates. This way you could do the following:

#set($url = $request.attributes.CURRENT_URL)
#set($singleValue = $httpUtil.getParameter($url, "foo", false))
#set($multipleValues = $httpUtil.getParameterMap($httpUtil.getQueryString($url)).foo)

I couldn't find the supposed solution in the terrible documentation, so i came up with this:

#set($curl = $request.get("attributes").get("CURRENT_URL"))
#set($foo = $curl.split("foo="))
<hr>
#if($foo.size() > 1)
  #set($foo1 = $foo.get(1).split("&").get(0))
  foo1: $foo1
#end
<hr>
#if($foo.size() > 2)
  #set($foo2 = $foo.get(2).split("&").get(0))
  foo2: $foo2
#end
<hr>
Green Lei
$request.getParameter("parameterName")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!