We help IT Professionals succeed at work.

How to fix a JSP custom tag error ?

sdesar
sdesar asked
on
Medium Priority
473 Views
Last Modified: 2013-11-24

What does this error mean and how to fix it --


org.apache.jasper.JasperException: /ExampleTag.jsp(8,7) Unable to load tag handler class "coreservlets.tags.ExampleTag" for tag "csajsp:example"

I am trying to simulate this example -  " Simple Example " - tag that outputs data to a JSP
http://shrek.wccnet.edu/~chasselb/java278/ClassNotes/jspTags/basics.htm


Awaiting a response !
Comment
Watch Question

do you have the .class files in the right place..

the must be under "web-inf" in a "classes" folder
do you know what I mean?
Ghost

Author

Commented:
The .class and the .java file are  in /WEB_INF/classes/src/abtest/ExampleTag.class
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
This is what i have in the ExampleTag.java
package coreservlets.tags;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;

/** Very simple JSP tag that just inserts a string
 *  ("Custom tag example...") into the output.
 *  The actual name of the tag is not defined here;
 *  that is given by the Tag Library Descriptor (TLD)
 *  file that is referenced by the taglib directive
 *  in the JSP file.
 *  
 */

public class ExampleTag extends TagSupport {
  public int doStartTag() {
    try {
      JspWriter out = pageContext.getOut();
      out.print("Custom tag example " +
                "(coreservlets.tags.ExampleTag)");
    } catch(IOException ioe) {
      System.out.println("Error in ExampleTag: " + ioe);
    }
    return(SKIP_BODY);
  }
}

Author

Commented:
OOPs I got it I put the above .java file in a dir called coreservlets/tags
that fixed it !
Thanks
here are your excellent points!
glad I can help,
thanks for the points,
ghost

Author

Commented:
Also, this test was to see how to output the data from a funstion I wrote.  Currently all the data is being outputted to the catalina.out logs.
Would you please advise on how to change the code below to output the data to the JSP itself --

here is the code

//Jsp Code

 <%@ page import = "src.abtest.*"
  import="java.util.*"
 
%>

<%@ taglib uri="taglib_tree.tld" prefix="tree" %>




<%
 ProjectNode projectNode=null;

projectNode= BmxServletUtilities.getProject(session);
JSPProperties JP = new JSPProperties();
String treeString = JP.recurseNode(projectNode, 0);
%>
<a href="http://www"> hello! </a>
<tree:createTree treePicture="tree.gif" nodePicture="leaf.gif" openPicture="open.gif" dhtml="true">
<%= treeString %>
</tree:createTree>

<BR>End Here




//Java Code


public String recurseNode(DbNode thisNode, int level) {
        final int maxLevel = 4;
        final StringBuffer resultBuffer = new StringBuffer();
        final NodeClassFilter filter = new NodeClassFilter();
        filter.accept(DefaultNode.class);
        filter.reject(SystemFolderNode.class);
        filter.reject(SystemFileNode.class);
        filter.reject(HistoryContainerNode.class);
        filter.reject(DeletedItemsFolderNode.class);
         // DbNode dbnode=(DbNode)thisNode.findNode(path);
        System.out.println("I am in recurseNode");
        // System.out.println("Node is: " + thisNode.getDisplayName());

        //DO STUFF HERE
        if (level == maxLevel) {
            //print out <tree with link

            // in JSP the tree tag looks like the comment below
            //<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.getName()+"</a>"%>'/>

            System.out.println("if loop");
           resultBuffer.append("<tree:addNode code='<%=\"<a href=http://www.yahoo.com\">");
           try {
                resultBuffer.append(thisNode.getName());
           } catch (CommandFailedException cfe) {
                Log.write(cfe);
           }
           resultBuffer.append("</a>%>'/>");
            System.out.println(resultBuffer);
        } else {
            //print without link
             System.out.println("else loop");
            resultBuffer.append("<tree:addNode code='");
            try {
                resultBuffer.append(thisNode.getName());
            } catch (CommandFailedException cfe) {
                Log.write(cfe);
            }

            resultBuffer.append("'>");
            System.out.println(resultBuffer);
        }
        synchronized (thisNode) {
            try {
                if ((thisNode.getChildCount() > 1) && (level < maxLevel)) {
                    final Enumeration thisNodeChildren = thisNode.children();
                    while (thisNodeChildren.hasMoreElements()) {
                        final Node thisNodeChild = (Node)(thisNodeChildren.nextElement());
                          System.out.println("I am in synchronized recurseNode");
                        if ((thisNodeChild instanceof DbNode) && (filter.accept(thisNode))) {
                            resultBuffer.append(recurseNode((DbNode)thisNodeChild, level+1));
                        }  // end inner if
                    }  // end while
                }  // end outer if
                 System.out.println("end tag");
               resultBuffer.append("</tree:addNode>");
           //      System.out.println(resultBuffer);
                return resultBuffer.toString();
            } catch (CommandFailedException cfe) {
                net.common.Log.write(cfe);
                return null;
            }
        }  // synchronized
    }  // end recurseNode


Eagerly awaiting a response!

Thanks!
use

out.println()

instead of
system.out.println()

anything else?
Ghost

Author

Commented:
I get an error -
cannot resolve symbol
symbol : variable out
out.println(resultBuffer);

awaiting a reponse

Thanks again!
well the out.println stuff can only be done in jsp

are we talking about jsp or java?
Gost

Author

Commented:
Its in the Java function recurseNode()
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.