Custom taglib problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy

    Custom taglib problems

    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.j sp.tagext.*;
    import javax.servlet.j sp.*;
    import java.io.*;

    public class HelloWorldTag extends TagSupport {

    public int doStartTag()
    throws JspException {

    try {
    JspWriter out = pageContext.get Out();
    out.println("<h 1>Hello world. Bet this doesn't work...
    Stupid Java</h1>");
    }
    catch (IOException ioexc) {
    throw new JspException(io exc.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:schemaLocat ion="http://java.sun.com/xml/ns/j2ee
    web-jsptaglibrary_2 _0.xsd"
    version="2.0">

    <tlibversion>1. 0</tlibversion>
    <jspversion>1.1 </jspversion>
    <shortname>hell o</shortname>
    <urn></urn>

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

    <tag>
    <name>hello</name>
    <tagclass>Hello WorldTag</tagclass>
    <info>Simples t 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
Working...