Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Tag NOT Compiling

 
Sanjay Deshpande
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dominic Paquette
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic