JSP tags in a Freemarker template

只愿长相守 提交于 2019-12-04 13:12:35

问题


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"] />

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"] />

回答1:


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>

can be used in FreeMarker via

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

At least this worked for me...



来源:https://stackoverflow.com/questions/7043191/jsp-tags-in-a-freemarker-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!