where to put .tld file while using spring boot and configged with completely java code

Deadly 提交于 2019-12-13 02:16:32

问题


In the old way, we put custom taglib description file at WEB-INF/xxx.tld, and JSP files load this file with <%@taglib prefix="xxx" uri="/META-INF/xxx.tld"%>

When we use Spring boot and config the application completely with java code (no web.xml, xxx-servlet.xml etc.), where to put it?

under resources/WEB-INF? or resources/META-INF?


回答1:


Just drop your tld in /src/main/webapp/WEB-INF/ and reference it from your jsp using the uri.

Example of tld located in /src/main/webapp/WEB-INF/

<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">

    <description>Example Tag Library</description>
    <tlib-version>4.0</tlib-version>
    <short-name>example</short-name>
    <uri>http://www.example.org/tags</uri>

    <tag>
       <name>exampleTag</name>
       <tag-class>com.example.taglib.ExampleTag</tag-class>
       <body-content>empty</body-content>
    </tag>
</taglib>

Example of referencing your tag library from a JSP file:

<%@ taglib prefix="ex" uri="http://www.example.org/tags"%>

And of course, using your custom tags:

<ex:exampleTag />

Hope it helps!




回答2:


As long as you're aware of the various JSP limitations, Spring Boot is sticking as much as possible to the "old way".

In that particular case, I don't think Spring Boot is involved at all in loading custom TLDs, but rather the container's job. Feel free to put it where it should be in regular WAR applications and raise an issue to the Spring Boot team with a repro project in case this doesn't work.



来源:https://stackoverflow.com/questions/37753819/where-to-put-tld-file-while-using-spring-boot-and-configged-with-completely-jav

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