• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Displaying Custom Tags in JSp

 
Niyali Kaul
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am using Tomacat 5.0.28 i have a problem while displaying the Custom tags in JSP.
The errors i get are


org.apache.jasper.JasperException: Unable to initialize TldLocationsCache: XML parsing error on file /WEB-INF/tlds/mytaglib.tld
org.apache.jasper.compiler.TldLocationsCache.init(TldLocationsCache.java:249)
org.apache.jasper.compiler.TldLocationsCache.getLocation(TldLocationsCache.java:220)
org.apache.jasper.JspCompilationContext.getTldLocation(JspCompilationContext.java:475)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:417)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1539)
org.apache.jasper.compiler.Parser.parse(Parser.java:126)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



My tld file is ----> The file is stored in /WEB-INF/tlds/mytglib.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">

<!-- a tag library descriptor -->

<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>first</shortname>
<uri>/WEB_INF/tlds</uri>
<info>A simple tab library for the
examples</info>

<tag>
<name>hello</name>
<tagclass>happy.tag.HelloTag</tagclass>
<bodycontent>empty</bodycontent>
<info>Say Hi</info>
</tag>
</taglib>

JSP FILE ---->

<%@ taglib uri="/WEB-INF/tlds/mytaglib.tld" prefix="first" %>
<HTML>
<HEAD>
<TITLE>Hello Tag</TITLE>
</HEAD>

<BODY bgcolor="#ffffcc">

<B>My first tag prints</B>:

<first:hello/>

</BODY>
</HTML>

web.xml file --->


<taglib>
<taglib-uri>/WEB-INF/tlds</taglib-uri>
<taglib-location>/WEB-INF/tlds/mytaglib.tld</taglib-location>
</taglib>






Tag File -->It is saved in directory /WEB-INF/classes/happy/tag/HelloTag.java

package tag;

import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class HelloTag implements Tag {
private PageContext pageContext;
private Tag parent;

public HelloTag() {
super();
}

public int doStartTag() throws JspException {
try {
pageContext.getOut().print("This is my first tag!");
} catch (IOException ioe) {}
return SKIP_BODY;
}

public int doEndTag() throws JspException {
return SKIP_PAGE;
}

public void release() {
}

public void setPageContext(PageContext
pageContext) {
this.pageContext = pageContext;
}

public void setParent(Tag parent) {
this.parent = parent;
}

public Tag getParent() {
return parent;
}
}



Please help me out .
can't figure out the problem
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The uri attribute in the taglib declaration in the jsp should have the value defined in the <taglib-uri> tag in web.xml. In your posting it has the value defined in the <taglib-location> tag.

ram.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't do anything. Simply use, <%@ taglib uri="/WEB-INF/tlds" prefix="first" %> in your jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML parsing error on file /WEB-INF/tlds/mytaglib.tld


You have a syntax error somewhere in your tld.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic