How to make custom tag work

The test.jsp works fine in my custom folder "tomcat-main-dir/webapps/lei".

Now I created a custom tag handler called "SimpleTag.java" and a mytaglib.tld file.

I put "SimpleTag.class" and mytaglib.tld in the "tomcat-main-dir/webapps/lei". When I run the .jsp, I got the following error msg:

root cause

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

An error occurred at line: -1 in the jsp file: null

Generated servlet error:

[javac] Compiling 1 source file

C:\jakarta-tomcat-4.1.7\work\Standalone\localhost\lei\test$jsp.java:79: cannot resolve symbol

symbol : class SimpleTag

location: class org.apache.jsp.test$jsp

SimpleTag _jspx_th_mytag_getSimpleTag_0 = (SimpleTag) _jspx_tagPool_mytag_getSimpleTag.get(SimpleTag.class);

^

C:\jakarta-tomcat-4.1.7\work\Standalone\localhost\lei\test$jsp.java:79: cannot resolve symbol

symbol : class SimpleTag

location: class org.apache.jsp.test$jsp

SimpleTag _jspx_th_mytag_getSimpleTag_0 = (SimpleTag) _jspx_tagPool_mytag_getSimpleTag.get(SimpleTag.class);

^

C:\jakarta-tomcat-4.1.7\work\Standalone\localhost\lei\test$jsp.java:79: cannot resolve symbol

symbol : class SimpleTag

location: class org.apache.jsp.test$jsp

SimpleTag _jspx_th_mytag_getSimpleTag_0 = (SimpleTag) _jspx_tagPool_mytag_getSimpleTag.get(SimpleTag.class);

mytaglib.tld is

<?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/dtd/web-jsptaglibrary_1_1.dtd">

<taglib>

<tlibversion>1.0</tlibversion>

<jspversion>1.1</jspversion>

<shortname>ToMytaglib</shortname>

<info>My first tag library descriptor file</info>

<tag>

<name>getSimpleTag</name>

<tagclass>SimpleTag</tagclass>

</tag>

</taglib>

and SimpleTag.java is

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

import java.io.*;

class SimpleTag extends TagSupport {

public int doStartTag() throws JspException {

try {

pageContext.getOut().print("Welcome to my Web site.");

} catch (IOException e) {

e.printStackTrace();

}

return SKIP_BODY;

}

}

How to make it work?

Any advice is appreciated.

Thanks,

[2525 byte] By [lei_developer] at [2007-9-27 14:06:58]
# 1
hi,how do u include in ur jsp,may be it can also have error.put ur jsp code as well in the forumvasanthct-usa
javavasanth at 2007-7-5 21:56:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

My .jsp file is pretty simple, as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ taglib uri="mytaglib.tld" prefix="mytag" %>

<html>

<head>

<title>Untitled</title>

</head>

<body>

<mytag:getSimpleTag />

</body>

</html>

lei_developer at 2007-7-5 21:56:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

The problem seems that the .class was put in a wrong place. But where should it go?

The following is complete info about the problem. Any advices are really appreciated.

Structure: /webapps/lei/WEB-INF/classes/

test.jsp is in /lei

mytaglib.tld is in /WEB-INF

SimpleTag.class is in /classes

****** test.jsp file ******

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ taglib uri="/WEB-INF/mytaglib.tld" prefix="mytag" %>

<html>

<head>

<title>Untitled</title>

</head>

<body>

Hello.

<mytag:getSimpleTag />

</body>

</html>

****** mytaglib.tld ******

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE taglib

PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"

"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>

<tlib-version>1.2</tlib-version>

<jsp-version>1.2</jsp-version>

<short-name>MyFirstTag</short-name>

<tag>

<name>getSimpleTag</name>

<tag-class>SimpleTag</tag-class>

</tag>

</taglib>

****** SimpleTag.java ******

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

import java.io.*;

public class SimpleTag extends TagSupport {

public int doStartTag() throws JspException {

try {

pageContext.getOut().print("Welcome to my Web site.");

} catch (IOException e) {

e.printStackTrace();

}

return SKIP_BODY;

}

}

When requesting "http://localhost:8080/lei/test.jsp", got the following error:

root cause

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

An error occurred at line: -1 in the jsp file: null

Generated servlet error:

[javac] Compiling 1 source file

C:\jakarta-tomcat-4.1.7\work\Standalone\localhost\lei\test$jsp.java:80: cannot resolve symbol

symbol : class SimpleTag

location: class org.apache.jsp.test$jsp

SimpleTag _jspx_th_mytag_getSimpleTag_0 = (SimpleTag) _jspx_tagPool_mytag_getSimpleTag.get(SimpleTag.class);

^

C:\jakarta-tomcat-4.1.7\work\Standalone\localhost\lei\test$jsp.java:80: cannot resolve symbol

symbol : class SimpleTag

location: class org.apache.jsp.test$jsp

SimpleTag _jspx_th_mytag_getSimpleTag_0 = (SimpleTag) _jspx_tagPool_mytag_getSimpleTag.get(SimpleTag.class);

^

C:\jakarta-tomcat-4.1.7\work\Standalone\localhost\lei\test$jsp.java:80: cannot resolve symbol

symbol : class SimpleTag

location: class org.apache.jsp.test$jsp

SimpleTag _jspx_th_mytag_getSimpleTag_0 = (SimpleTag) _jspx_tagPool_mytag_getSimpleTag.get(SimpleTag.class);

^

3 errors

Thanks,

lei_developer at 2007-7-5 21:56:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
I have been having the same problem. Were you able to find a solution? If you have any idea's I would really appreciate it. ThanksRizzy_ma
rizzy_ma at 2007-7-5 21:56:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

In test.jsp the taglib tag should be

<%@ taglib uri="/mytaglib" prefix="mytag" %>

instead of

<%@ taglib uri="/WEB-INF/mytaglib.tld" prefix="mytag" %>

In web application deployment descriptor web.xml include a taglib element:

<taglib>

<taglib-uri>mytaglib</taglib-uri>

<tablig-location>WEB-INF/mytaglib.tld</taglib-location>

</taglib>

dvohra09 at 2007-7-5 21:56:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
I too was getting similar kind of error. I could overcome this by creating my class(that extendsTagSupport) in a package and mentioning the classname with package heirarchy in the 'tagclass' tag.
satish_r at 2007-7-5 21:56:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...