By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

Custom taglib problems

P: n/a
Hi all,

Custom taglibs are driving me nuts! I'm trying to install a sample
from the book I'm learning from, and it just falls over.

Here's my class, which compiles without any problems:

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

public class HelloWorldTag extends TagSupport {

public int doStartTag()
throws JspException {

try {
JspWriter out = pageContext.getOut();
out.println("<h1>Hello world. Bet this doesn't work...
Stupid Java</h1>");
}
catch (IOException ioexc) {
throw new JspException(ioexc.toString());
}

return SKIP_BODY;
}
public int doEndTag() {
return EVAL_PAGE;
}
}

Here's my tld, which is in WEB-INF under my web app's root directory:

<?xml version="1.0" encoding="UTF-8"?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
web-jsptaglibrary_2_0.xsd"
version="2.0">

<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>hello</shortname>
<urn></urn>

<info>
HelloWorld taglib that won't work
</info>

<tag>
<name>hello</name>
<tagclass>HelloWorldTag</tagclass>
<info>Simplest example: inserts one line of output</info>
</tag>

</taglib>

I also tried using and old DTD version of the tld, which didn't work
at all. At least I get an error message now...

When I try and load a page with a reference to the taglib, eg:

<%@ taglib uri="WEB-INF/hello.tld" prefix="mytag" %>
<html>
<head>
<title>2-6 on not working</title>
</head>
<body bgcolor=white>

<mytag:hello/>

</body>
</html>

It says:

XML parsing error on file /WEB-INF/hello.tld: (line 3, col 8):
Document is invalid: no grammar found.

I'm guessing this is a schema problem, but can anyone help me clear
this up?

Thanks in advance,
Andy
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.