aspose file tools*
The moose likes JSP and the fly likes Custom Tag  NOT Compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom Tag  NOT Compiling" Watch "Custom Tag  NOT Compiling" New topic
Author

Custom Tag NOT Compiling

Sanjay Deshpande
Ranch Hand

Joined: May 22, 2001
Posts: 111
I have a tag file :
import java.io.IOException;
import java.util.Date;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
// Hello tag accepting a name attribute.
public class AttribHelloTag extends TagSupport
{
private String name;
// Property getter for name
public String getName() {
return name;
}
// Property setter for name
public void setName(String name) {
this.name = name;
}
public int doEndTag() throws JspTagException {
String dateString = new Date().toString();
try {
pageContext.getOut().write("Hello <b>" + name + "</b>.<br/>");
pageContext.getOut().write("My name is " + getClass().getName() +
" and it's " + dateString + "<p/>");
}
catch (IOException ex) {
throw new JspTagException("Hello tag could not write to JSP out");
}
return EVAL_PAGE;
}
}
==================================
I m getting error:
1.following not found.
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
2. extends TagSupport not found..
Any solution?
How to write a tag? what is needed?
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
In order to compile the tag you must have the servlet/jsp apis within your classpath. If you are using Tomcat 4.0 then simply putting
%TOMCAT_HOME%/common/lib/servlet.jar
in your class path will do the trick.
Hope this helps
Sam


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Dominic Paquette
Ranch Hand

Joined: Dec 13, 2002
Posts: 64
Hi,
From what I understand, your compiler can't find the javax.servlet.jsp and javax.servlet.tagext packages. In order for your compiler to find these packages, you need to tell him where they are. To do this, you use the classpath for example:
javac -classpath c:\j2sdkee\lib\j2ee.jar AttribHelloTag.java
Hope this helps
Dominic
Sanjay Deshpande
Ranch Hand

Joined: May 22, 2001
Posts: 111
HI , Thnx for the reply.
i m using tomcat3.3 and have this in class path
C:\TomCat\jakarta-tomcat-3.3a\lib\common\servlet.jar
however , this is not working for me.
What could be the problem?
Sanjay Deshpande
Ranch Hand

Joined: May 22, 2001
Posts: 111
My tag has comiLped.
i have tld like this :
---------------------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//
DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/
web-jsptaglibrary_1_1.dtd">
<!-- a tag library descriptor -->
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>first</shortname>
<uri></uri>
<info>A simple tab library for the
examples</info>
<tag>
<name>hello</name>
<tagclass>HelloTag</tagclass>
<bodycontent>empty</bodycontent>
<info>Say Hi</info>
</tag>
</taglib>
--------------------------------------
HERE IS MY WEB.XML:
-------------------------------------
<taglib>
<taglib-uri>mytags</taglib-uri>
<taglib-location>/WEB-INF/jsp/mytaglib.tld</taglib-location>
</taglib>
--------------------------------------
HERE IS MY JSP:
-------------------------------------
%@ taglib uri="/WEB-INF/jsp/mytaglib.tld"
prefix="first" %>
<HTML>
<HEAD>
<TITLE>Hello Tag</TITLE>
</HEAD>
<BODY bgcolor="#ffffcc">
<B>My first tag prints</B>:
<first:hello/>
</BODY>
</HTML>
-------------------------------------
I GET FOLLOWING ERROR:
PLZ LEMME KNOW THE SOLUTION
org.apache.jasper.compiler.CompileException: C:\TomCat\jakarta-tomcat-3.3a\webapps\examples\jsp\Hellotag.jsp(0,0) Unable to open taglibrary /WEB-INF/jsp/mytaglib.tld : Parse Error in the tag library descriptor: External entity not found: "http://java.sun.com/j2ee/dtds/
web-jsptaglibrary_1_1.dtd".
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
There doesn't appear to be a problem with deployment descriptor or you tld as the compiler actually finds the tag class. Make sure the package exists in the jar and make sure it is in the classpath.


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Something that I have noticed from your TLD file is that you've not specified a package for your tag handler class. For custom tags to work properly, you should place your tag handler class inside a package.
Cheers
Simon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom Tag NOT Compiling
 
Similar Threads
JSP Custom Tag Lib
Not a valid tag lib
STEP-BY-STEP creating a WAR file
Problem with Custom Tags
TagExtraInfo Question