【问题标题】:TLD specifies invalid body-content (EMPTY) for custom tagTLD 为自定义标签指定无效的正文内容 (EMPTY)
【发布时间】:2015-06-27 16:41:17
【问题描述】:

我有这个错误:“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标签有什么问题。

【问题讨论】:

  • 嘿@jessicathaisa 我的回答对你有帮助吗?
  • 嗨,@milind-j。是的,它确实!帮助很大。谢谢!

标签: java jsp jsp-tags taglib


【解决方案1】:
<?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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 2016-01-28
    • 1970-01-01
    • 2015-05-07
    • 2013-02-03
    • 1970-01-01
    • 2011-12-03
    相关资源
    最近更新 更多