• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Custom tag error

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 687
Hibernate jQuery Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry,
I tried it. but the problem remains??Any other suggesions
Prasad
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Prasad P Nair
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The .tld is in web-inf and the .class is in web-inf/classes
 
reply
    Bookmark Topic Watch Topic
  • New Topic