[英]How to solve this problem with JSP tag extension?

Begining with JSP and servlet development, I have some problems with a bodyless custom tag to be inserted in a JSP page.


Steps done:

  1. Wrote and compiled successfully a CustomTag.java (extending TagSupport) in WEB-INF/classes directory;
  2. 在WEB-INF / classes目錄中成功編寫並編譯了CustomTag.java(擴展TagSupport);

  3. Defined the TLD file, with a very simple example, including <body-content> with an empty value for a bodyless tag;
  4. 定義了TLD文件,其中包含一個非常簡單的示例,包括 ,其中包含無體標記的空值;

  5. Used the tag in a JSP page with taglib directive pointing to my /WEB-INF/tlds/site.tld file.
  6. 在JSP頁面中使用標記,taglib指令指向我的/WEB-INF/tlds/site.tld文件。

With all this in mind, do you have a clue why Tomcat is sending an error like this:


CustomTag cannot be resolved to a type


Thanks in advance for your answers, and please ask if you need more details.


Here's my TLD file:


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

< ! DOCTYPE taglib 
    PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" 

    <description>Custom library.</description>

The JSP file:


<%@ 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">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <clib:header />

The HeaderTag class:


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 {
        catch (IOException e) {
            throw new JspTagException("Error.");
        return EVAL_PAGE;

1 个解决方案


You've rebuilt and redeployed, correct? In that case my best guess is that you left out the <tag-class> directive in the TLD file.

你重建並重新部署了,對嗎?在這種情況下,我最好的猜測是你遺漏了TLD文件中的 指令。


If that isn't the cause, please post your TLD file and an example JSP.


Edit: All tag classes must have a package. Per the JSP 2.0 spec (section JSP 11.2):

編輯:所有標記類都必須包含一個包。根據JSP 2.0規范(JSP 11.2節):

As of JSP 2.0, it is illegal to refer to any classes from the unnamed (a.k.a. default) package.

從JSP 2.0開始,引用未命名(a.k.a.default)包中的任何類是非法的。



  © 2014-2022 ITdaan.com 联系我们: