TLD为自定义标记指定了无效的正文内容(EMPTY)

时间:2015-04-20 19:25:15

标签: java jsp jsp-tags taglib

我有这样的错误:" TLD为自定义标签mundo指定无效的正文内容(EMPTY)" 这个taglib的创建有什么问题?

AlomMundoTLD.jsp

    <%-- 
        Document   : alomundoTLD
        Created on : 20/04/2015, 15:59:42
        Author     : Jessica
    --%>

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ taglib uri="AloMundo.tld" prefix="alo" %>

    <!DOCTYPE html> <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title><alo:mundo /> JTLB</title>
        </head>
        <body>
            <h1><alo:mundo /></h1>
        </body> </html>

AloMundo.tld

<?xml version="1.0" encoding="UTF-8"?> <taglib version="2.1" 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">   <tlibversion>1.0</tlibversion>   <jspversion>1.1</jspversion>   <shortname>alo</shortname>   <info>TabLib de Alo Mundo!!!</info>   <tag>
      <name>mundo</name>
      <tagclass> tagLib.AloMundo</tagclass>
      <info>Devolve Alo Mundo</info>
      <bodycontent>EMPTY</bodycontent>   </tag> </taglib>

AloMundo.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tagLib;

import java.io.IOException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

/**
 *
 * @author Jessica
 */
public class AloMundo extends TagSupport  {
    public int doStartTag(){
        JspWriter saida = pageContext.getOut();
        try{
            saida.print("Alo mundo!!!");
        }
        catch (IOException e){
            e.printStackTrace();
        }

        return SKIP_BODY;
    }
}

请帮我识别上述jsp标签中的错误。

1 个答案:

答案 0 :(得分:0)

<?xml version="1.0" encoding="UTF-8"?> <taglib version="2.1" 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">   <tlibversion>1.0</tlibversion>   <jspversion>1.1</jspversion>   <shortname>alo</shortname>   <info>TabLib de Alo Mundo!!!</info>   <tag>
  <name>mundo</name>
  <tagclass> tagLib.AloMundo</tagclass>
  <info>Devolve Alo Mundo</info>
  <bodycontent>empty</bodycontent>   </tag> </taglib> 

您的身体内容需要为空,而不是根据XSD的EMPTY,如下所示:

<xsd:simpleContent>
      <xsd:restriction base="javaee:string">
    <xsd:enumeration value="tagdependent"/>
    <xsd:enumeration value="JSP"/>
    <xsd:enumeration value="empty"/>
    <xsd:enumeration value="scriptless"/>
      </xsd:restriction>
    </xsd:simpleContent>