• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with Custom Tags

 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,
I have a problem which I think is because I am overlooking something small but important..but I don't know what..
Here is my .tld file:
<?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">
<taglib>
<!-- ============== Tag Library Description Elements each tag is defined by a tag element============= -->
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>test</shortname>
<uri>/MyTag</uri>
<tag>
<name>hello</name>
<tagclass>com.myprojects.MyTag</tagclass>
<info>This is an sample tag which out puts Hello and a short message when used.</info>
</tag>
</taglib>

Here is my simple jsp:
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/MyTag.tld" prefix="test" %>
<html>
<head>
<title>Hello This is my first CustomTag</title>
</head>
<body bgcolor="white">
<UL>
<LI><test:hello/>
</UL>
</body>
</html>
My customtag class is simple & compiles fine. Somebody tell me what I the problem is when I try to run the jsp in tomcat I get the following error.
javax.servlet.ServletException: com/myprojects/MyTag (wrong name: MyTag)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:484)

Thanks,
Roopa.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you let us know the location of your class file and the .tld file?
Where are you placing them wrt to your JSP?
Edited:
An additional piece of info that will be helpful - What version of Tomcat are you running?
- satya
[ February 11, 2002: Message edited by: Madhav Lakkapragada ]
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am putting the class files in WEB-INF/classes and the .tld file under WEB-INF.
I am running Tomcat 4.0.1
Originally posted by Madhav Lakkapragada:
Could you let us know the location of your class file and the .tld file?
Where are you placing them wrt to your JSP?
Edited:
An additional piece of info that will be helpful - What version of Tomcat are you running?
- satya
[ February 11, 2002: Message edited by: Madhav Lakkapragada ]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<tagclass>com.myprojects.MyTag</tagclass>
putting the class files in WEB-INF/classes

The class files need to be in WEB-INF/classes/com/myprojects directory.

running Tomcat 4.0.1
In Tomcat 4.0.1, you need to define a taglib tag in the DD (web.xml) and specify the location of the TLD file. Only then the TLD file will be loaded correctly. This apparently is a bug.
So in the web.xml of your application add this, if you haven't already done so.

Try this and let us know....
Good luck.
- satya
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And BTW, your TLD follows JSP 1.1 Specs.
So make sure that the MyTag.java follows the API for 1.1 JSP Spec and that you don't try to use the latest and greatest Interfaces.
The unfortunate fact is according to Tomcat 4.0.1, both the implementations compile correctly. So it is your responsibility to follow the correct API.
Let us know what happens, when you get a chance.
regds.
- satya
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satya,
I actually had everything in place just like you suggested. MyTag has the following src code
package com.myprojects;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.math.*;
public class MyTag extends TagSupport
{
public int doStartTag()
{
try
{
JspWriter out = pageContext.getOut();
out.print("Hello!!This message is from the custom tag MyTag class");
}
catch(IOException io)
{
System.out.println("Error generating the string message from MyTag class: ");
}
return (SKIP_BODY);
}
}
It is a very simple class.. I am still getting the following error
javax.servlet.ServletException: com/myprojects/MyTag (wrong name: MyTag)
java.lang.NoClassDefFoundError: com/myprojects/MyTag (wrong name: MyTag)
Can u think of anything else that I might be doing wrong.
Roopa.
Originally posted by Madhav Lakkapragada:
And BTW, your TLD follows JSP 1.1 Specs.
So make sure that the MyTag.java follows the API for 1.1 JSP Spec and that you don't try to use the latest and greatest Interfaces.
The unfortunate fact is according to Tomcat 4.0.1, both the implementations compile correctly. So it is your responsibility to follow the correct API.
Let us know what happens, when you get a chance.
regds.
- satya
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can suggest two things....
1. Use a relative URI in the taglib of your JSP like this:
<%@ taglib uri="MyTag.tld" prefix="test" %>
Then place the TLD file in the same dir that
your JSP is. If it works you know that its not
a problem with your class file.
2. If you are on a Windows system, verify that
each dir/file is named properly wrt to the case-sensitivity of a fin/dir name. Windows doesn't
differentiate between "mytag.tld" and "MyTag.tld".
So please double check each file involved.
3. Your tag declaration in the TLD doesn't have a
<bodycontent> element. I would like to suggest
that you put the foll. line after the tagclass element.
<bodycontent>empty</bodycontent>
This maynot be a big deal, but just for completeness sake. I know this was an issue in 3.8.?? versions of Tomcat.
Good luck.
- satya
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic