freemarker如何获取页面请求的参数
展开全部
在ftl页面这样写:
${req.getParameter("categoryname")}
但是假如你要用<#if 指令让${req.getParameter("categoryname")}参与比较呢?有一个小地方要注意一下:
正确写法:
1)
<#list pagesdatas as ls>
<#if ls.newscategory.id?default("") = ‘${req.getParameter("categoryname")}‘>
.....................
</#if>
</#list>
2)
<#list pagesdatas as ls>
<#if ls.newscategory.id?default("") = "${req.getParameter(‘categoryname‘)}">
.....................
</#if>
</#list>
3
<#list pagesdatas as ls>
<#if ls.newscategory.id?default("") = "${req.getParameter(\"categoryname\")}">
.....................
</#if>
</#list>
错误写法:
<#list pagesdatas as ls>
<#if ls.newscategory.id?default("") = "${req.getParameter("categoryname")}">
.....................
</#if>
</#list>
原因:估记应该是4个双引号冲突了
补充:把${req.getParameter("categoryname")}赋值给变量的正确写法:
1)<#assign var ="${req.getParameter(‘categoryname‘)}">
2) <#assign var =‘${req.getParameter(‘categoryname‘)}‘>
3)<#assign var ="${req.getParameter(\"categoryname\")}">
${req.getParameter("categoryname")}
但是假如你要用<#if 指令让${req.getParameter("categoryname")}参与比较呢?有一个小地方要注意一下:
正确写法:
1)
<#list pagesdatas as ls>
<#if ls.newscategory.id?default("") = ‘${req.getParameter("categoryname")}‘>
.....................
</#if>
</#list>
2)
<#list pagesdatas as ls>
<#if ls.newscategory.id?default("") = "${req.getParameter(‘categoryname‘)}">
.....................
</#if>
</#list>
3
<#list pagesdatas as ls>
<#if ls.newscategory.id?default("") = "${req.getParameter(\"categoryname\")}">
.....................
</#if>
</#list>
错误写法:
<#list pagesdatas as ls>
<#if ls.newscategory.id?default("") = "${req.getParameter("categoryname")}">
.....................
</#if>
</#list>
原因:估记应该是4个双引号冲突了
补充:把${req.getParameter("categoryname")}赋值给变量的正确写法:
1)<#assign var ="${req.getParameter(‘categoryname‘)}">
2) <#assign var =‘${req.getParameter(‘categoryname‘)}‘>
3)<#assign var ="${req.getParameter(\"categoryname\")}">
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询