代码之家  ›  专栏  ›  技术社区  ›  Ankur

为什么<taglib>在web.xml中给了我一个问题

  •  22
  • Ankur  · 技术社区  · 16 年前

    我有这个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 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
       <display-name>jsp-tags</display-name>
         <taglib>
           <taglib-uri>mytags</taglib-uri>
           <taglib-location>/WEB-INF/mytaglib.tld</taglib-location>
        </taglib>
        <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
       </welcome-file-list> 
    </web-app>
    

    突出显示,并且IDE给出的错误是:“从元素开始发现无效内容…

    我还需要做什么?

    3 回复  |  直到 10 年前
        1
  •  47
  •   Jaydeep Patel    16 年前

    使用此符号:

    <jsp-config> 
            <taglib> 
                   <taglib-uri>mytags</taglib-uri> 
                   <taglib-location>/WEB-INF/jsp/mytaglib.tld</taglib-location> 
            </taglib> 
    </jsp-config>
    

    但我建议你读这个 link . 本教程将向您介绍如何在JSP 2.0的情况下避免在web.xml中声明taglibs。

        2
  •  6
  •   Synesso    16 年前

    在XML中引用的XSD中,它指出对于复杂类型的Web AppType,只能选择0到以下许多元素:

    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:group ref="javaee:descriptionGroup"/>
      <xsd:element name="distributable"
     type="javaee:emptyType"/>
      <xsd:element name="context-param"
     type="javaee:param-valueType">
    
      </xsd:element>
      <xsd:element name="filter"
     type="javaee:filterType"/>
      <xsd:element name="filter-mapping"
     type="javaee:filter-mappingType"/>
      <xsd:element name="listener"
     type="javaee:listenerType"/>
      <xsd:element name="servlet"
     type="javaee:servletType"/>
      <xsd:element name="servlet-mapping"
     type="javaee:servlet-mappingType"/>
      <xsd:element name="session-config"
     type="javaee:session-configType"/>
      <xsd:element name="mime-mapping"
     type="javaee:mime-mappingType"/>
      <xsd:element name="welcome-file-list"
     type="javaee:welcome-file-listType"/>
      <xsd:element name="error-page"
     type="javaee:error-pageType"/>
      <xsd:element name="jsp-config"
     type="javaee:jsp-configType"/>
      <xsd:element name="security-constraint"
     type="javaee:security-constraintType"/>
      <xsd:element name="login-config"
     type="javaee:login-configType"/>
      <xsd:element name="security-role"
     type="javaee:security-roleType"/>
      <xsd:group ref="javaee:jndiEnvironmentRefsGroup"/>
      <xsd:element name="message-destination"
     type="javaee:message-destinationType"/>
      <xsd:element name="locale-encoding-mapping-list"
     type="javaee:locale-encoding-mapping-listType"/>
    </xsd:choice>
    

    在XSD中根本没有引用taglib元素。

    从阅读 this link 似乎您不需要在Web应用程序文档中声明taglibs。只要具有version=“2.5”属性,就意味着您可以引用JSP中的标记。

        3
  •  0
  •   Daniel De León    10 年前

    如果taglib在 马文依赖, 只需设置要编译的范围。

    <dependency>
         <groupId>org.apache.struts</groupId>
         <artifactId>struts-taglib</artifactId>
         <version>1.3.10</version>
         <scope>compile</scope>
    </dependency>