Search code examples
javajspjsp-tagstaglib

TLD specifies invalid body-content (EMPTY) for custom tag


I have this error: "TLD specifies invalid body-content (EMPTY) for custom tag mundo" What is wrong with this taglib creation?

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;
    }
}

Please help me to identify what is wrong in the above jsp tag.


Solution

  • <?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> 
    

    Your body content need to be empty and not EMPTY as per the XSD as below:

    <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>