使用Spring Boot并使用完全Java代码进行配置时在哪里放置.tld文件 [英] where to put .tld file while using spring boot and configged with completely java code
问题描述
以旧方式,我们将自定义taglib描述文件放在WEB-INF/xxx.tld中,而JSP文件使用<%@taglib prefix="xxx" uri="/META-INF/xxx.tld"%>
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"%>
当我们使用Spring boot并用Java代码(没有web.xml,xxx-servlet.xml等)完全配置应用程序时,放在哪里?
When we use Spring boot and config the application completely with java code (no web.xml, xxx-servlet.xml etc.), where to put it?
在资源/WEB-INF下?或资源/META-INF?
under resources/WEB-INF? or resources/META-INF?
推荐答案
只需将您的tld放在/src/main/webapp/WEB-INF/中,然后使用uri从您的jsp中引用它即可.
Just drop your tld in /src/main/webapp/WEB-INF/ and reference it from your jsp using the uri.
位于/src/main/webapp/WEB-INF/
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>
从JSP文件引用标签库的示例:
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 />
希望有帮助!
这篇关于使用Spring Boot并使用完全Java代码进行配置时在哪里放置.tld文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!