Jason
Jason

Reputation: 353

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

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?

Upvotes: 2

Views: 5629

Answers (2)

Ramon Rius
Ramon Rius

Reputation: 424

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!

Upvotes: 3

Brian Clozel
Brian Clozel

Reputation: 59211

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.

Upvotes: 0

Related Questions