J2EE: Implementing custom tag handler

C

Christine Mayer

Hi,

I am trying to implement my own custom tag handler, but it doesn't
work :-(
What I did so far:

1. I wrote a Handler class like this:

public class MyHandler extends SimpleTagSupport {

public void doTag() throws JspException, IOException{

getJspContext().getOut().write("test");
}
}
2. In my project I added jsp-api-2.0.jar to be able to import the
necessary packages
javax.servlet.jsp.JspException and
javax.servlet.jsp.tagext.SimpleTagSupport

3. I added this jar as a maven dependency for deployment

4. I wrote a tld file and put it in WEB-INF/mytld.tld
<?xml version="1.0" encoding="ISO-8859-1" ?>
<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">

<tlib-version>0.1</tlib-version>
<short-name>myshortname</short-name>
<uri>myuri</uri>
<tag>
<description>My Desc</description>
<name>myname</name>
<tag-class>com.mycompany.MyClass</tag-class>
<body-content>empty</body-content>
<attribute>
<name>myattribute</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
5. I added a tag lib directive to my jsps:
<%@ taglib prefix="t" uri="myuri"%>

6. I used the tag in my jsp like that:
<t:myname myattribute="myValue" />

However, it didn't work, instead, I got this weird error:

org.apache.jasper.JasperException: /WEB-INF/jsp/myfile.jsp(1,1) Unable
to read TLD "META-INF/tlds/struts-tiles-1.1.tld" from JAR file "file:/
D:/MyFolder/tomcat/webapps/myWebApp/WEB-INF/lib/struts-1.2.7.jar":
org.apache.jasper.JasperException: Failed to load or instantiate
TagExtraInfo class: org.apache.struts.taglib.tiles.UseAttributeTei

org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:
39)

I am using the tiles tag lib of struts, which workes perfectly, when I
undo the steps described above.
But as soon as I add the jsp-api-2.0.jar I get this error.

Any idea what's wrong and how to fix this?

Thanks in advance,

Christine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top