Dear friends,
I am new to JSP custom tags. I wrote a tag to find the sum of two numbers. For this, I wrote a tag library descriptor(.tld) file, tag handler class and the implementing JSP file. In the beginning, everything worked fine. But whenever, I add new tags along with setter and getter methods or modify the existing tag, it shows the following error message:
org.apache.jasper.JasperException: /custom_tags.jsp(1,0) Unable to find setter method for attribute: first
My tag library code:
<?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>1.2</tlibversion>
<jspversion>1.1</jspversion>
<shortname>sum</shortname>
<uri>tag_lib.tld</uri>
<tag>
<name>sum</name>
<tagclass>strutsproj.tag.SumTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>first</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>second</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
</taglib>
My tag handler class:
package strutsproj.tag;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class SumTag extends TagSupport {
String first = null;
String second = null;
public int doEndTag() throws JspException {
try {
pageContext.getOut().print("Sum = "+(getFirst() + getSecond()));
} catch(java.io.IOException ioe) {
}
return SKIP_BODY;
}
public int doStartTag() throws JspException {
return EVAL_PAGE;
}
public void setFirst(String first) {
this.first = first;
}
public int getFirst() {
return Integer.parseInt(this.first);
}
public void setSecond(String second) {
this.second = second;
}
public int getSecond() {
if(this.second != null)return Integer.parseInt(this.second);
return 0;
}
}
My JSP page:
<%@ taglib uri="/WEB-INF/tld/tag_lib.tld" prefix="dt" %>
<dt:sum first="5" second="7"/>
I am using Tomcat 4.1.18
What might have caused that error?