错误org.apache.jasper.JasperException:java.lang.ClassNotFoundException

时间:2017-05-29 08:16:30

标签: java jsp custom-tags

我试图创建一个简单的自定义标记JSP应用程序,或者我不断收到此错误,或者有时Unable to load tag handler class "HelloTag" for tag "ex:Hello". 我的index.jsp看起来像这样:

<%@page contentType="text/html;charset=UTF-8" language="java" %>

<%@taglib prefix="ex" uri="WEB-INF/custom.tld"%>
<html lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>customised tag</title>
</head>
<body>
<ex:Hello/>
</body>
</html>

来自WEB-INF的我的custom.tld如下所示:

<taglib>
   <tlib-version>1.0</tlib-version>
   <jsp-version>2.0</jsp-version>
   <short-name>Example TLD</short-name>

   <tag>
      <name>Hello</name>
      <tag-class>HelloTag</tag-class>
      <body-content>empty</body-content>

   </tag>
</taglib>

这是来自WEB-INF / classes的Java类HelloTag.java

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


public class HelloTag extends SimpleTagSupport {
   public void doTag() throws JspException, IOException {
      JspWriter out = getJspContext().getOut();
      out.write("Hello Custom Tag!");
   }
}

整个错误日志:

exception

org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.labJavaIJ.web.index_jsp
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:177)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:376)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.ClassNotFoundException: org.apache.jsp.labJavaIJ.web.index_jsp
    java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:132)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:376)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

0 个答案:

没有答案