标记文件目录 /WEB-INF/functions.tld 不以“/WEB-INF/tags”开头

Tag file directory /WEB-INF/functions.tld does not start with "/WEB-INF/tags"

我有一个有趣的问题...我正在尝试向我的应用程序添加一个 JSP 标签。我在 /WEB-INF/tags/ 中存储了一个 functions.tld 但我收到错误消息 Illegal TLD path /WEB-INF/tags/functions.tld, must not start with "/WEB-INF/tags" 所以我尝试移动它 /WEB-INF/ 然后我得到 Tag file directory /WEB-INF/functions.tld does not start with "/WEB-INF/tags"。那我应该把它放在哪里呢!!

顶级域名文件

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

    <tlib-version>1.0</tlib-version>
    <short-name>my</short-name>

    <!-- Invoke 'Generate' action to add tags or functions -->
    <function>
        <name>urlencode</name>
        <function-class>library.StringUtils</function-class>
        <function-signature>java.lang.String urlencode(java.lang.String)</function-signature>
    </function>

</taglib>

JSP 文件

<%@ taglib prefix="f" tagdir="/WEB-INF/tags/functions.tld" %>

不在标记文件夹中时出错

org.apache.jasper.JasperException: PWC6191: Tag file directory /WEB-INF/functions.tld does not start with "/WEB-INF/tags"

在 /tag/ 文件夹中时出错

  Error invoking ServletContainerInitializer org.apache.jasper.runtime.TldScanner
org.apache.jasper.JasperException: PWC6336: Illegal TLD path /WEB-INF/tags/functions.tld, must not start with "/WEB-INF/tags"
    at org.apache.jasper.runtime.TldScanner.processTldsInFileSystem(TldScanner.java:573)
    at org.apache.jasper.runtime.TldScanner.processTldsInFileSystem(TldScanner.java:566)
    at org.apache.jasper.runtime.TldScanner.scanTlds(TldScanner.java:354)
    at org.apache.jasper.runtime.TldScanner.onStartup(TldScanner.java:242)
    at org.apache.catalina.core.StandardContext.callServletContainerInitializers(StandardContext.java:5713)
    at com.sun.enterprise.web.WebModule.callServletContainerInitializers(WebModule.java:623)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5609)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:540)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:900)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:684)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2044)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1690)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:107)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
  Startup of context  failed due to previous errors]]

这是一个简单的误解。稍微推理一下,使用属性 tagdir 来引用单个标签 file 没有多大意义。正确的实现方式是确实将TLD文件放在WEB-INF目录下,然后使用

引用
<%@ taglib prefix="f" uri="/WEB-INF/functions.tld" %>

换句话说:将tagdir替换为uri

这个 existing question 和答案解释了区别。