java - 信息 : TLD skipped. URI:<标记名称 URI> 已定义

标签 java jsp tomcat web.xml taglib

我有一个 Web 应用程序正在从 Tomcat 5.5.35 迁移到 Tomcat 7.0.39。目前,有几个自定义标签库,每个都在自己的 tld 中定义。文件。这是一个例子:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>customTag</short-name>
    <uri>http://www.something.com/util/customTag-db-taglib</uri>
    <description>
        Database tag library for Util 
    </description>
    <tag>
        <name>useBean</name>
        <tag-class>com.mx.releasemgr.tags.db.UseBeanTag</tag-class>
        <tei-class>com.mx.releasemgr.tags.db.UseBeanTEI</tei-class>
        <body-content>EMPTY</body-content>
        <attribute>
            <name>id</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>oid</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>oidParameter</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>type</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>scope</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
    ...
</taglib>

WEB-INF 中只有一个此 tld 文件的副本文件夹。它从未被放入 jar 中文件。

web.xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
  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-app_3_0.xsd" version="3.0">
...
<jsp-config>
     <taglib>
    <taglib-uri>customTag</taglib-uri>
    <taglib-location>/WEB-INF/customTag.tld</taglib-location>
</taglib>
</jsp-config>
...

此错误出现在 catalina.out

Apr 11, 2013 3:50:08 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.mx.com/releasemgr/releasemgr-db-taglib is already defined

标签库是这样导入的:

<%@ taglib uri="customTag" prefix="db" %>

我看过this question但它似乎并不适用。我添加了 <jsp-config> ,没用。我叫 taglib 错了吗? URI 参数是否正确?感谢您的帮助。

最佳答案

规范要求的 URI 的优先顺序是:

  1. J2EE 平台标签库 - Tomcat 不提供这些
  2. web.xml 条目
  3. WEB-INF/lib 中的 JARS 和 WEB-INF 下的 TLD(同等优先级)
  4. 容器中的其他条目

你的 tld 被加载了两次,第一次来自 web.xml,第二次来自 WEB-INF 及其子文件夹中的扫描。

解决办法是

1、从web.xml中移除

2、把你的tld文件放到/WEB-INF/tags/


好吧,这只是一个小故事。如果您想了解更多。

1、tomcat 5.5也有同样的逻辑,只是不做烦人的日志。

2、tomcat启动时出现该日志。在 tomcat 启动时加载 tld 用于在 tld 文件中寻找监听器。

3、真正在jsp中使用tld就是另外一回事了。

当第一个jsp被编译时,tomcat会为uri和location对建立一个缓存。

uri加载来自同一个订单

1) web.xml 条目,标签 uri 从 web.xml 中获取

2) 扫描WEB-INF下的tld文件,从tld文件中获取标签uri

3) 扫描jar,从tld文件中获取标签uri。

所以在您的配置中,customTag.tld 注册了 2 个 uri,customTag 和 http://www.mx.com/releasemgr/releasemgr-db-taglib

4) tomcat 启动时。它加载 tld 以在 tld 文件中查找监听器。

从 web.xml 加载时,它会同时放置 customTag(来自 web.xml)和 http://www.mx.com/releasemgr/releasemgr-db-taglib(from tld 文件) 成一个集合。

从 WEB-INF 加载时,uri 来自 tld 文件,即 ttp://www.mx.com/releasemgr/releasemgr-db-taglib。 Tomcat 需要避免重复添加 tld 监听器,因此它会检查集合中是否存在 uri。如果 uri 已经存在,它会记录消息并跳过添加 tld 监听器。

将它们放在一起,

1、如果你的tld文件中没有监听器,Tomcat启动时不需要扫描tld。 您可以通过在上下文中将 processTlds 设置为 false 来禁用。

当第一个jsp被编译时,tomcat会为uri和location对建立一个缓存。

2,您可以忽略该警告。这只是为了避免在 tld 文件中重复加载监听器。

关于java - 信息 : TLD skipped. URI:<标记名称 URI> 已定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15958392/

相关文章:

java - Tomcat 上的 Websockets : how to shutdown the server cleanly?

java - JBoss 绑定(bind) IP 地址

java - JSF:资源组件是否优化?

java - 在枚举内映射

java - 通过代码创建AEM包

javascript - 我怎么知道用户正在输入或粘贴?

java - 如何将 2 个变量与 <c :if> 进行比较

javax.el.PropertyNotFoundException :

tomcat - 在 IntelliJ 中运行 Tomcat 时,如何更改控制台中 [INFO] 的颜色?

java - 在 Java 中设置为相等 : by value or reference?