在freemarker中获取请求属性
如何检查 freemarker 中请求属性的值? 我尝试了 <#if *${RequestParameters['servicesettings']} ??>但出现错误 ->
在行中遇到“*”
有人可以帮忙吗?
How do I check a value from the request attribute in freemarker?
I tried <#if *${RequestParameters['servicesettings']} ??> but getting errors ->
Encountered "*" at line
Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它取决于Web应用程序框架,因为FreeMarker本身不公开请求参数。 (嗯,除非框架使用 Freemareker.ext.servlet.FreemarkerServlet ,它是 FreeMarker 的扩展。)此外,通常您不应该直接从 MVC< /em> 模板,或任何特定于 HTTP/Servlet 的内容。
截至错误消息,您所写的内容有一些语法错误...可能您的意思是
<#if RequestParameters.servicesettings??>
(它不是 JSP - 不要使用${...}
-s 在 FreeMarker 标签内)。这将要求您在数据模型中具有RequestParameters
,但我无法确定......It depends on the Web application framework, because FreeMarker itself doesn't expose the request parameters. (Well, except if the framework uses
freemareker.ext.servlet.FreemarkerServlet
which is kind of an extension to FreeMarker.) Also, usually you shouldn't access request parameters directly from an MVC template, or anything that is HTTP/Servlet specific.As of the error message, what you have written has a few syntax errors... probably you meant
<#if RequestParameters.servicesettings??>
(it's not JSP - don't use${...}
-s inside FreeMarker tags). This will require that you haveRequestParameters
in the data-model, that I can't know for sure...我们应该这样写:
We should write like this:
你可以使用
You can use
根据 FreemarkerServlet 的 JavaDoc :
您可以简单地编写:
获取请求属性的值(您可能已使用
request.setAttribute('attrName', 'value') 在 servlet 请求过滤器中设置了该值
与 Freemarker 一起为我工作 <代码>2.3.27-孵化
According to the JavaDoc of the
FreemarkerServlet
:You can simply write:
to get the value of a request attribute (that you might have set in a servlet request filter using
request.setAttribute('attrName', 'value')
Worked for me with Freemarker
2.3.27-incubating