Hi,
Begining with JSP and servlet development, I have some problems with a bodyless custom tag to be inserted in a JSP page.
Steps done:
- Wrote and compiled successfully a CustomTag.java (extending
TagSupport
) inWEB-INF/classes
directory; - Defined the TLD file, with a very simple example, including
<body-content>
with anempty
value for a bodyless tag; - Used the tag in a JSP page with taglib directive pointing to my
/WEB-INF/tlds/site.tld
file.
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"
"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>
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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>title</title>
</head>
<body>
<clib:header />
</body>
</html>
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 {
pageContext.getOut().print("<p>header</p>");
}
catch (IOException e) {
throw new JspTagException("Error.");
}
return EVAL_PAGE;
}
}