首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么<taglib>在我的web.xml中给我一个问题?

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

Stack Overflow用户
提问于 2010-09-23 11:21:47
回答 3查看 54.4K关注 0票数 24

我有这个web.xml

代码语言:javascript
复制
<?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给出的错误是:“找到以元素开头的无效内容...

我还需要做些什么?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-09-23 13:21:02

使用此表示法:

代码语言:javascript
复制
<jsp-config> 
        <taglib> 
               <taglib-uri>mytags</taglib-uri> 
               <taglib-location>/WEB-INF/jsp/mytaglib.tld</taglib-location> 
        </taglib> 
</jsp-config>

但我推荐阅读这篇link。本教程将向您介绍在JSP2.0中如何避免在web.xml中声明标记库

票数 54
EN

Stack Overflow用户

发布于 2010-09-23 11:35:30

在XML中引用的XSD中,它指出对于复杂类型web-appType,您只能选择以下元素中的零到多个:

代码语言:javascript
复制
<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应用程序文档中声明标记库。简单地拥有version="2.5“属性就意味着您可以在JSP中引用标记。

票数 7
EN

Stack Overflow用户

发布于 2016-01-05 08:31:41

如果标记库位于maven依赖项中,只需将作用域设置为编译即可。

代码语言:javascript
复制
<dependency>
     <groupId>org.apache.struts</groupId>
     <artifactId>struts-taglib</artifactId>
     <version>1.3.10</version>
     <scope>compile</scope>
</dependency>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3775264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档