0

我尝试在 Apache 7 中创建一个简单的 jsp 自定义标签(空标签)示例。在解析 web.xml 文件期间出现错误,“在解析 web.xml 期间,taglib 定义与特定版本不一致”。文件如下。请帮助我

<!--Web.xml-->
<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"
    id="WebApp_ID" version="3.0" >
<!--
To register a TLD with the context and associating a unique URI that can be further used to refer this TLD. This is an optional declaration, you![enter image description here][1] can refer the TLD directly, I will explain you the other options of referring the TLD in JSP page after this example
 -->
    <taglib>
        <taglib-uri>mytags</taglib-uri>
        <taglib-location>/WEB-INF/MyTags.tld</taglib-location>
    </taglib>
</web-app>

<!--MyTags.tld-->
<!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.1</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>exampletags</short-name>
    <info>Example Custom Tags</info>
    <uri>http://www.mysite.com/jspexamples/exampletags</uri>

    <tag>
        <name>getMessage</name>
        <tag-class>com.santosh.jspex.customtags.HelloTagHandler</tag-class>
        <body-content>empty</body-content>
    </tag>
</taglib>

<!--TestPage.jsp-->
<!--
To declare the taglib definations making the translator aware of the custom tags which we have defined
-->
<%@taglib uri="mytags" prefix="exampletags"%>

<html> <body>
<b>Response of getMessage tag : </b> <i> <exampletags:getMessage/> </i>
<br>
</body></html>
<!--a tag handler class is defined -->
4

1 回答 1

0

您的web.xml元素是根据pre 2.5 servlet spec定义的。因为您使用的是2.5发布 2.5(3.0) servlet 规范,请执行以下操作:

<jsp-config> 
 <taglib>
        <taglib-uri>mytags</taglib-uri>
        <taglib-location>/WEB-INF/MyTags.tld</taglib-location>
 </taglib>
<jsp-config> 
于 2013-08-10T07:45:06.637 回答