I am working with custom tags in Java and I am getting an error. Let me detail below the files involved:
My tag.tld (path is: \WEB-INF\tlds\tag.tld) has the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>0.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>message</shortname>
<tag>
<description>StringReverseTag</description>
<name>string</name>
<tag-class>mytag.StringReverseTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>data</name>
<required>true</required>
</attribute>
</tag>
</taglib>
ReverseEx.jsp
<%@page contentType="text/html" pageEncoding="UTF-8" language="java"%>
<!DOCTYPE html>
<%@taglib uri="/WEB-INF/tlds/tag.tld" prefix="jen" %>
<jen:string data="EARTH"/>
<html>
<head>
<title>Tag Example</title>
</head>
<body>
</body>
</html>
Helper class:
package chap4;
import java.io.IOException;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
public class StringReverseTag extends SimpleTagSupport{
private String data;
public void setData(String data) {
this.data=data;
}
@Override
public void doTag() throws JspException, IOException{
JspWriter out = getJspContext().getOut();
StringBuffer sb= new StringBuffer(data);
sb.reverse();
out.print(sb);
}
}
The error I get is the following:
org.apache.jasper.JasperException: file: ...Struts/Struts/build/web/ReverseEx.jsp(10,0) PWC6032: Unable to load tag handler class "mytag.StringReverseTag" for tag "jen:string" org.apache.jasper.JasperException: PWC6032: Unable to load tag handler class "mytag.StringReverseTag" for tag "jen:string" ...Struts/Struts/build/web/ReverseEx.jsp(10,0) ...Struts\Struts\nbproject\build-impl.xml:924: Java returned: 1 BUILD FAILED (total time: 2 seconds)
What am I doing wrong?
in your tag.tld file you write:
<tag-class>mytag.StringReverseTag</tag-class>
this means: your class StringReverseTag
should be in myTag
package.
but in your code of StringReverseTag
i can see that you have chap4
as package!
to solve your problem just change:
<tag-class>mytag.StringReverseTag</tag-class>
to
<tag-class>chap4.StringReverseTag</tag-class>