如何在jsp文件中使用freemarker标签库?
我想知道如果可能的话如何在 jsp 文件中使用 freemarker 标记库。我使用的是Struts2框架。目前,我没有足够的带宽将项目中的所有 jsp 文件转换为 ftl 文件,因此出现了难题。
我查看了 http://freemarker.sourceforge.net/docs/pgui_misc_servlet.html#autoid_57< /a> 但它并没有说太多。
I wanted to know how, if possible, to use freemarker tag library in a jsp file. I am using the Struts2 framework. Currently I do not have the bandwidth to convert all the jsp files in my project in to ftl file, hence the conundrum.
I checked out http://freemarker.sourceforge.net/docs/pgui_misc_servlet.html#autoid_57 but it does not really say much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我们在工作中一直在做同样的事情,并且我们为放入 JSP 中的每个模板创建了一个带有标签的自定义标签库。
例如:
我们有productSpecs.ftl,它正在替换产品页面上的一些内容。
我们创建了一个 taglib(名为 ftl)并放入我们的 JSP 中。
我们做了一些 Java 魔法,以便我们的标签库中的每个标签都有一个 Java 类。换句话说,有一个名为 ProductSpecs.java 的类,它基本上只是加载同名的 ftl 文件,并将其与我们的 JSON 数据结合起来,并将输出写入 html 中。
工作量比我上面详细介绍的要多一些,但我的观点是这是完全可能的。
We have been doing the same thing where I work and we've created a custom taglib with tags for each of the templates we've put into our JSPs.
For example:
We have productSpecs.ftl that is replacing some content on a product page.
We've created a taglib (named ftl) and are putting in our JSPs.
We have done some Java magic so that we have a Java class for each tag in our taglib. In other words, there's a class called ProductSpecs.java that basically just loads the ftl file by the same name and combines it with our JSON data and writes the output in html.
There's a little more work than what I've detailed above, but my point is that it's totally possible.
如果您想用免费标记模板代替标准 struts2 模板,我相信框架提供了对此的扩展。
FreeMarker 标签是框架提供的通用 Struts 标签 的扩展。您只需了解可以访问标签的通用结构即可直接进入:
<@s.tag>; ...
,其中 tag 是框架支持的任何标签。更多详细信息请参阅官方文档。
Freemarker-tags
If you want to Free marker template in place of standard struts2 template than i believe framework provides an extension to this.
FreeMarker tags are extensions of the generic Struts Tags provided by the framework. You can jump right in just by knowing the generic structure in which the tags can be accessed:
<@s.tag> ...</@s.tag>
, where tag is any of the tags supported by the framework.For more details refer to the official doc.
Freemarker-tags
Struts 2 标签库以 JSP 标签、Velocity 标签和 Freemarker 标签实现。每种视图层技术的语法略有不同,但都有详细记录。
http://struts.apache.org/2.x/docs/struts -tags.html
The Struts 2 tag library is implemented in JSP tags, Velocity tags, and Freemarker tags. The syntax is slightly different for each view layer technology, but it's all well documented.
http://struts.apache.org/2.x/docs/struts-tags.html
您不能在 JSP 文件中使用 FreeMarker 指令(标签)(除非有人为此编写了 JSP 标签库,但我强烈怀疑这一点)。 (FreeMarker 模板可以使用 JSP 标签,但有限制,但这不是您要问的。)
You can't use FreeMarker directives (tags) in a JSP file (unless someone has written a JSP taglib for that, but I strongly doubt that). (FreeMarker templates can use JSP tags, with limitations, but that's not what you are asking.)
我找到了此标签的javadocs: http://freemarker.sourceforge .net/docs/api/freemarker/ext/jsp/FreemarkerTag.html
但我确实没有找到任何使用它的例子。它应该做你所说的事情,我正在寻找同样的事情。
I found the javadocs for this tag: http://freemarker.sourceforge.net/docs/api/freemarker/ext/jsp/FreemarkerTag.html
But I really didn't find any examples using it. It should do the thing you're saying, I'm looking for the same thing.