facebook

Error while using custom tags

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #249503 Reply

    vinodnn
    Member

    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?

    #249539

    Riyad Kalla
    Member

    Honestly I think this is a cache issue. Try restarting MyEclipse and rebuilding your project. Also your URI may be wrong depending on what is in your web.xml file, be sure to read this: http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-10906.html

    Also, you might just want to use JSTL libs and the expression language to accomplish all this.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Error while using custom tags

You must be logged in to post in the forum log in