JSP Custom Tag lib problem !!

kmthien

Senior member
Oct 8, 2002
363
0
0
Hi,

I got a problem here with tag lib !

/usr/local/tomcat5/webapps/Wrox/Libraries/WEB-INF/custom/timeTag.java
========================================================
package custom;

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.text.SimpleDateFormat;

public class timeTag extends TagSupport
{
String format = "HH:mm:ss";

// public void setFormat(String newFormat)
// {
// format = newFormat;
// }
public int doEndTag() throws JspException
{
SimpleDateFormat sdf;
sdf = new SimpleDateFormat(format);
String time = sdf.format(new java.util.Date());
try
{
pageContext.getOut().print(time);
}
catch (Exception e)
{
throw new JspException(e.toString());
}
return EVAL_PAGE;
}
}
========================================================

/usr/local/tomcat5/webapps/Wrox/Libraries/WEB-INF/exampleTags.tld
========================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
version="2.0">
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>ExampleTags</short-name>
<description>A set of example tag handlers.</description>
<tag>
<name>time</name>
<tag-class>custom.timeTag</tag-class>
</tag>
</taglib>
========================================================

usr/local/tomcat5/webapps/Wrox/Libraries/currentTime.jsp
========================================================
<%@ taglib prefix="example" uri="/WEB-INF/exampleTags.tld" %>
<html>
<head></head>
<body>
Welcome to my webpage. The current time is <example:time />
</body>
</html>
========================================================

When I tried to display the currentTime.jsp, I got the error as follows:

=======================================================
exception

org.apache.jasper.JasperException: /Libraries/currentTime.jsp(5,47) Unable to load tag handler class "custom.timeTag" for tag "example:time"
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:83)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:402)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1358)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1646)
org.apache.jasper.compiler.Parser.parse(Parser.java:173)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:247)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:149)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:135)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:243)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:285)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:232)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
=======================================================

pls help ....
 

chsh1ca

Golden Member
Feb 17, 2003
1,179
0
0
Originally posted by: kmthien
Hi,
I got a problem here with tag lib !

/usr/local/tomcat5/webapps/Wrox/Libraries/WEB-INF/custom/timeTag.java
========================================================
package custom;

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.text.SimpleDateFormat;

public class timeTag extends TagSupport

Knowing absolutely jack about JSP, and only being a java developers for console apps at the moment, I'd take a venture that your compile error is because of some kind of actual error withing timeTag.java (syntactical or otherwise). The import javax.servlet.js.tagext.*; is redundant since it should be imported when it processes the import javax.servlet.jsp.*;, and are you certain that you should be extending the TagSupport class, and not implementing a TagSupport interface? It could make sense either way -- like I said, I haven't touched JSP. :) Those are just some guesses.