Tomcat 8 找不到自定义顶级域名
Tomcat 8 cannot find custom tlds
我用 spring 引导创建了一个网站。
现在,
我想将其转换为可以在 Tomcat 8 中部署。
转换后,
Tomcat 8 无法找到我的自定义 TLD 文件,
即使我在 web.xml.
设置 'taglib-location'
这是我的项目源
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<!-- tld -->
<jsp-config>
<taglib>
<taglib-uri>/tld/code-generator.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/code-generator.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
代码-generator.tld
<?xml version="1.0" encoding="UTF-8" ?>
<taglib version="2.1"
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/javaee/web-jsptaglibrary_2_1.xsd" >
<tlib-version>1.0</tlib-version>
<short-name>cdg</short-name>
<uri>/WEB-INF/tld/code-generator.tld</uri>
<function>
<name>toCodeString</name>
<function-class>com.msh.nia.util.CodeGenerator</function-class>
<function-signature>java.lang.String toCodeString(java.lang.String)</function-signature>
</function>
... etc
index.jsp
<%@ taglib prefix="cdg" uri="/tld/code-generator.tld" %>
目录结构:
structure image
错误和警告
정보: Starting Servlet Engine: Apache Tomcat/8.5.34
10월 17, 2018 11:48:05 오후 org.apache.jasper.servlet.TldScanner scanJspConfig
경고: Failed to process TLD with path [/WEB-INF/tld/code-generator.tld] and URI [/tld/code-generator.tld]. The specified path does not exist.
10월 17, 2018 11:48:05 오후 org.apache.jasper.servlet.TldScanner scanJars
정보: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
10월 17, 2018 11:48:05 오후 org.apache.catalina.core.ApplicationContext log
정보: 2 Spring WebApplicationInitializers detected on classpath
...
2018-10-17 23:48:16.026 INFO 73568 --- [ main] o.a.c.s.Catalina : Server startup in 14987 ms
2018-10-17 23:48:16.314 ERROR 73568 --- [nio-8080-exec-9] o.s.b.w.s.s.ErrorPageFilter : Forwarding to error page from request [/index.jsp] due to exception [Unable to find taglib [cdg] for URI: [tld/code-generator.tld]]
org.apache.jasper.JasperException: Unable to find taglib [cdg] for URI: [tld/code-generator.tld]
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:55) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:293) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:80) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:181) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:431) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:489) ~[jasper.jar:8.5.34]
您似乎在 web.xml 文件的 taglib-location 元素中提供了绝对路径。
试试这个:
<taglib-location>WEB-INF/tld/code-generator.tld</taglib-location>
注意元素值中 "WEB-INF" 前没有“/”。
我用 spring 引导创建了一个网站。 现在, 我想将其转换为可以在 Tomcat 8 中部署。 转换后, Tomcat 8 无法找到我的自定义 TLD 文件, 即使我在 web.xml.
设置 'taglib-location'这是我的项目源
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<!-- tld -->
<jsp-config>
<taglib>
<taglib-uri>/tld/code-generator.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/code-generator.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
代码-generator.tld
<?xml version="1.0" encoding="UTF-8" ?>
<taglib version="2.1"
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/javaee/web-jsptaglibrary_2_1.xsd" >
<tlib-version>1.0</tlib-version>
<short-name>cdg</short-name>
<uri>/WEB-INF/tld/code-generator.tld</uri>
<function>
<name>toCodeString</name>
<function-class>com.msh.nia.util.CodeGenerator</function-class>
<function-signature>java.lang.String toCodeString(java.lang.String)</function-signature>
</function>
... etc
index.jsp
<%@ taglib prefix="cdg" uri="/tld/code-generator.tld" %>
目录结构: structure image
错误和警告
정보: Starting Servlet Engine: Apache Tomcat/8.5.34
10월 17, 2018 11:48:05 오후 org.apache.jasper.servlet.TldScanner scanJspConfig
경고: Failed to process TLD with path [/WEB-INF/tld/code-generator.tld] and URI [/tld/code-generator.tld]. The specified path does not exist.
10월 17, 2018 11:48:05 오후 org.apache.jasper.servlet.TldScanner scanJars
정보: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
10월 17, 2018 11:48:05 오후 org.apache.catalina.core.ApplicationContext log
정보: 2 Spring WebApplicationInitializers detected on classpath
...
2018-10-17 23:48:16.026 INFO 73568 --- [ main] o.a.c.s.Catalina : Server startup in 14987 ms
2018-10-17 23:48:16.314 ERROR 73568 --- [nio-8080-exec-9] o.s.b.w.s.s.ErrorPageFilter : Forwarding to error page from request [/index.jsp] due to exception [Unable to find taglib [cdg] for URI: [tld/code-generator.tld]]
org.apache.jasper.JasperException: Unable to find taglib [cdg] for URI: [tld/code-generator.tld]
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:55) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:293) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:80) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:181) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:431) ~[jasper.jar:8.5.34]
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:489) ~[jasper.jar:8.5.34]
您似乎在 web.xml 文件的 taglib-location 元素中提供了绝对路径。
试试这个:
<taglib-location>WEB-INF/tld/code-generator.tld</taglib-location>
注意元素值中 "WEB-INF" 前没有“/”。