Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compilation error using Custom Tags

Status
Not open for further replies.

knowitnot

Programmer
Jun 7, 2004
15
US
hi.

i'm having some difficulty working with a simple custom tag. when i load the jsp file, i receive a runtime error that reads...

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 1 in the jsp file: /MySimplePage.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Tomcat\work\Catalina\localhost\myJSPApp\org\apache\jsp\MySimplePage_jsp.java:42: ';' expected
taglib uri="/myTLD" prefix="easy"
^
1 error

here's the tld file
<taglib>
<taglibversion>1.0</taglibversion>
<shortname></shortname>
<name>myTag</name>
<tagclass>com.brainysoftware.MyCustomTag</tagclass>
</taglib>

here's the customtag class
package com.brainysoftware;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class MyCustomTag extends TagSupport {

public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
out.println("Hello from the custom tag.");
}
catch (Exception e) {
}
return super.doEndTag();
}
}

and finally here's the deployment descriptor web.xml
<display-name>template</display-name>
<taglib>
<taglib-uri>/myTLD</taglib-uri>
<taglib-location>/WEB-INF/taglib.tld</taglib-location>
</taglib>
</web-app>

all the files are in the correct directory structure but i can't seem to find the problem. any help would be appreciated.
 
one more thing i left out... =P

the jsp file!

<% taglib uri="/myTLD" prefix="easy" %>
<easy:myTag/>
 
Hi,

You need to change your tld file.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "[URL unfurl="true"]http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">[/URL]
<taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>mt</shortname>
    <uri></uri>
    <info>My first Tag library</info>
    <tag>
        <name>myTag</name>
        <tagclass>examples.taglib.MyCustomTag</tagclass>
        <bodycontent>empty</bodycontent>

    </tag>
</taglib>

In the jsp page use the taglib

<%@ taglib uri="/WEB-INF/myTag.tld" prefix="my"%>

<my:myTag/>

in web.xml

<taglib>
<taglib-uri>myTag</taglib-uri>
<taglib-location>/WEB-INF/myTag.tld</taglib-location>
</taglib>

Cheers
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top