1

I'm trying to use the following class in a JSP-based custom tag:

public class HelloWorldTest {
    public void hello1() { }
}

The tag file is in WEB-INF/tags/hello.tag:

<%@ tag language="java" pageEncoding="ISO-8859-1" %>
<% HelloWorldTest hello; %>

I'm trying to use the tag from index.jsp:

<%@taglib tagdir="/WEB-INF/tags" prefix="my"%&gt;
<%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
<html>
  <body>
    <my:hello></my:hello>
  </body>
</html>

I get the following exception:

org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:178)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

The problem is trying to use the HelloWorldTest class, because a tag without it works fine:

<%@ tag language="java" pageEncoding="ISO-8859-1" %>
<% for(int i = 0; i < 5; i++) { %>
  <%= i %>
<% } %>
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Alex
  • 329
  • 2
  • 17
  • 1
    Where are you importing packages in your code? – Lion Nov 20 '11 at 16:12
  • thank you, i replaced HelloWorldTest to src/mypackage/ and added `code <%@ tag import="mypackage.HelloWorldTest" %>` to hello.tag – Alex Nov 20 '11 at 16:38

1 Answers1

2

You need to actually import the class with an import directive.

<%@ page import="my.package.HelloWorld" %>

(Where my.package is replaced with your class's actual package.)

Dave Newton
  • 158,873
  • 26
  • 254
  • 302