Question

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 %>
<% } %>
Was it helpful?

Solution

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top