Freemarker模板中的JSP标记 [英] JSP tags in a Freemarker template

查看:116
本文介绍了Freemarker模板中的JSP标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在freemarker模板中使用一些自定义标签,这很容易,因为我可以在我的web.xml文件中包含JspSupportServlet并在模板中包含以下行。

I want to use some custom tags in a freemarker template which is easy enough as I can include the JspSupportServlet in my web.xml file and include the folowing line in the template.

<#assign my=JspTaglibs["/WEB-INF/mytaglib.tld"] />

但是,如果.tld捆绑在META内的JAR文件中,我该怎么做呢? -INF目录?我试过这两个都没有运气。

However how do I go about doing this if the .tld is bundled in a JAR file inside the META-INF directory? I tried both of these with no luck.

<#assign my=JspTaglibs["/META-INF/mytaglib.tld"] />
<#assign my=JspTaglibs["/mynamespace"] />


推荐答案

FreeMarker会自动扫描WEB-INF中的所有JAR文件/ lib目录。如果它在JAR的META-INF目录中找到.tld文件,就像你的META-INF / mytaglib.tld一样,它会在里面查看,以便找到< uri> 标签。如果找到一个,它将通过此​​URI使taglib可用,例如定义为

FreeMarker automatically scans all JAR files in your WEB-INF/lib directory. If it finds .tld files inside a JAR's META-INF directory, like your META-INF/mytaglib.tld, it will peek inside it in order to find the <uri> tag. If it finds one, it will make the taglib available via this URI, e.g a taglib defined like

<taglib>
  <shortname>my custom taglib</shortname>
  <uri>http://example.org/mytaglib</uri>
  <!-- ... -->
</taglib>

可以在FreeMarker中使用

can be used in FreeMarker via

<#assign my=JspTaglibs["http://example.org/mytaglib"] />

至少这对我有用...

At least this worked for me...

这篇关于Freemarker模板中的JSP标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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