wood burning stoves 2.0*
The moose likes JSP and the fly likes Custom tag error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom tag error" Watch "Custom tag error" New topic
Author

Custom tag error

Prasad P Nair
Greenhorn

Joined: Nov 22, 2002
Posts: 10
Hi i'm new bie in custom tags. While experimenting with the stuff, i got the folowing error. Can anybody sort it out??
Cheers
Prasad
I'm attaching the codes..\
myTag.java
-------------------------------------------------
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
class myTag implements Tag{
private PageContext pageContext;
private Tag parent;
public myTag(){
super();
}
public int doStartTag() throws JspTagException{
return SKIP_BODY;
}
public int doEndTag() throws JspTagException{
try{
pageContext.getOut().write("Hello world byb prasad");
}catch(java.io.IOException e){
throw new JspTagException("IO exception"+e.getMessage());
}
return EVAL_PAGE;
}
public void release(){}
public void setPageContext(PageContext pContext){
this.pageContext=pContext;
}
public void setParent(Tag parent){
this.parent=parent;
}
public Tag getParent(){
return this.parent;
}
}
mytags.tld
-------------------------------------------------
<?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>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>my</shortname>
<tag>
<name>hello</name>
<tagclass>myTag</tagclass>
<bodycontent>empty</bodycontent>
<info>My Tag</info>
</tag>
</taglib>
body.jsp
--------------------------------------------------
<%@ taglib uri="/WEB-INF/mytags.tld" prefix="my" %>
<--------------------------
<br><br><br><br><br>====<b>Body 1</b>====<br><br><br><br><br>
<my:hello />

Error i got
--------------------------------------------------
[ServletException in:body.jsp] Unable to compile class for JSP An error occurred at line: 7 in the jsp file: /body.jsp Generated servlet error: C:\Tomcat4.0\work\Standalone\localhost\Tiles\body$jsp.java:63: Class org.apache.jsp.myTag not found. myTag _jspx_th_my_hello_0 = new myTag(); ^ An error occurred at line: 7 in the jsp file: /body.jsp Generated servlet error: C:\Tomcat4.0\work\Standalone\localhost\Tiles\body$jsp.java:63: Class org.apache.jsp.myTag not found. myTag _jspx_th_my_hello_0 = new myTag(); ^ 2 errors ' org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 7 in the jsp file: /body.jsp Generated servlet error: C:\Tomcat4.0\work\Standalone\localhost\Tiles\body$jsp.java:63: Class org.apache.jsp.myTag not found. myTag _jspx_th_my_hello_0 = new myTag(); ^ An error occurred at line: 7 in the jsp file: /body.jsp Generated servlet error: C:\Tomcat4.0\work\Standalone\localhost\Tiles\body$jsp.java:63: Class org.apache.jsp.myTag not found. myTag _jspx_th_my_hello_0 = new myTag(); ^ 2 errors at org.apache.jasper.compiler.Compiler.compile(Compiler.java:285) at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:548) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:176) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:188) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683) at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574) at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497) at org.apache.jasper.runtime.JspRuntimeLibrary
Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

Hi Prasad
as u can see from the error logs the compiler is trying to find the class MyTag in "org.apache.jsp.myTag" this is so becos u do not have a package structure defined for u'r tag and hence the compiler will try to find the class in its class path or the default classpath(i think if u add the current directory to the classpath the problem may be solved though i am not too sure about that).
what u can do is put the tag in a package say
package tag.MyTag
and change the taglib entry to
<tagclass>tag.myTag</tagclass>
i hope this solves u'r problem.
Devesh
Prasad P Nair
Greenhorn

Joined: Nov 22, 2002
Posts: 10
Sorry,
I tried it. but the problem remains??Any other suggesions
Prasad
Thomas Hubschman
Ranch Hand

Joined: Sep 25, 2002
Posts: 88
Prasad,
This seems to be the main error:
Unable to compile class for JSP An error occurred at line: 7 in the jsp file: /body.jsp Generated servlet error: C:\Tomcat4.0\work\Standalone\localhost\Tiles\body$jsp.java:63: Class org.apache.jsp.myTag not found.
The server is looking for your tag in the package 'org.apache.jsp.myTag'
Where infact is the tag located? In WEB-INF/classes?


SCJP '02, SCWCD '02, SCJD '08, SCSNB '09, SCEA '10
Prasad P Nair
Greenhorn

Joined: Nov 22, 2002
Posts: 10
The .tld is in web-inf and the .class is in web-inf/classes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom tag error
 
Similar Threads
A error occured on JSP custom tag...
Package...not found in import
Bean class not found error...
import directives for taglib classes?
jsp when compiled cant find bean class see code servlet exception