Question

avec JSP et Begining développement de servlet, j'ai quelques problèmes avec une étiquette personnalisée bodyless à insérer dans une page JSP.

Les étapes faites:

  1. A écrit et compilé avec succès un CustomTag.java (extension TagSupport) dans le répertoire de WEB-INF/classes;
  2. défini par le fichier TLD, avec un exemple très simple, y compris <body-content> avec une valeur empty pour une balise bodyless;
  3. Utilisé la balise dans une page JSP avec la directive taglib pointant vers mon fichier /WEB-INF/tlds/site.tld.

Avec tout cela à l'esprit, avez-vous une idée de pourquoi Tomcat envoie une erreur comme ceci:

  

CustomTag ne peut être résolu à un type

Merci d'avance pour vos réponses, et s'il vous plaît demander si vous avez besoin de plus de détails.


Voici mon fichier TLD:

<?xml version="1.0" encoding="ISO-8859-1"?>

< ! 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.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>customlib</short-name>
    <description>Custom library.</description>
    <tag>
      <name>header</name>
      <tag-class>HeaderTag</tag-class>
      <body-content>empty</body-content>
      <description>...</description>
    </tag>
</taglib>

Le fichier JSP:

<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib uri="/WEB-INF/tlds/customlib.tld" prefix="clib" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>title</title>
</head>

<body>
    <clib:header />
</body>
</html>

La classe HeaderTag:

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

public class HeaderTag extends TagSupport {

    public int doEndTag() throws JspTagException {
        try {
            pageContext.getOut().print("<p>header</p>");
        }
        catch (IOException e) {
            throw new JspTagException("Error.");
        }
        return EVAL_PAGE;
    }
}
Était-ce utile?

La solution

Vous avez rebâti et redéployés, non? Dans ce cas, ma meilleure estimation est que vous avez quitté la directive dans le fichier TLD.

<tag>
    <name>cookieIterator</name>
    <tag-class>util.infoTemplates.CookieIterator</tag-class>
    <body-content>JSP</body-content>
</tag>

Si ce n'est pas la cause, s'il vous plaît publier votre fichier TLD et un exemple JSP.


Edit: Toutes les classes d'étiquette doivent avoir un paquet. Par la spécification JSP 2.0 (section JSP 11.2):

  

JSP 2.0, il est illégal de se référer à toutes les classes de l'innommé (alias   package par défaut).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top