jsp jar无法加载

时间:2011-05-02 13:15:18

标签: jsp tomcat servlets jsp-tags

/var/lib/tomcat6/webapps/ROOT我有以下结构=>

META-INF  teiExample.jsp  WEB-INF

./META-INF:
context.xml

./WEB-INF:
exampleTags.tld  lib  web.xml

./WEB-INF/lib:
example.jar

example.jar =>

的内容
META-INF/
META-INF/MANIFEST.MF
classes/utilities/arrayExtraInfo.class
classes/utilities/createArrayTag.class
exampleTags.tld

teiExample.jsp =>

<%@ taglib prefix="example" uri="exampleURI" %>
<html>

<head>
    <title>Welcome and time example</title>
</head>

<body>

<example:createArray name="theArray" />
We are now using a JAR file<BR />
The array has <%= theArray.length %> items.<BR />

</body>
</html>

exampleTags.tld =&gt;

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>ExampleTags</short-name>
    <uri>exampleURI</uri>
    <description>A set of example tag handlers.</description>

    <tag>
        <name>createArray</name>
        <tag-class>utilities.createArrayTag</tag-class>
        <tei-class>utilities.arrayExtraInfo</tei-class>
        <attribute>
            <name>name</name>
        </attribute>
    </tag>
</taglib>

web.xml =&gt;

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
    <taglib>
        <taglib-uri>exampleTags</taglib-uri>
        <taglib-location>/WEB-INF/exampleTags.tld</taglib-location>
    </taglib>
</web-app>

但我得到的只是=&gt;

    HTTP Status 500 - 

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 
org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class: utilities.arrayExtraInfo
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:281)
    org.apache.jasper.compiler.TagLibraryInfoImpl.createTagInfo(TagLibraryInfoImpl.java:419)
    org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:250)
    org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:163)
    org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:382)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:445)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1392)
    org.apache.jasper.compiler.Parser.parse(Parser.java:130)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:170)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 
java.lang.ClassNotFoundException: utilities.arrayExtraInfo
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1484)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1329)
    org.apache.jasper.compiler.TagLibraryInfoImpl.createTagInfo(TagLibraryInfoImpl.java:416)
    org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:250)
    org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:163)
    org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:382)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:445)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1392)
    org.apache.jasper.compiler.Parser.parse(Parser.java:130)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:170)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.
Apache Tomcat/6.0.24

为什么请?而且,我是否需要web.xml

1 个答案:

答案 0 :(得分:1)

  

org.apache.jasper.JasperException:无法加载或实例化TagExtraInfo类:utilities.arrayExtraInfo

这仅仅意味着在幕后

TagExtraInfo tag = (TagExtraInfo) Class.forName("utilities.arrayExtraInfo").newInstance(); 

失败了。

即。要么类不在类路径中,要么没有默认的无参数构造函数。然而,真正的根本原因应该存在于堆栈跟踪中。在堆栈跟踪中进一步阅读,最底部是问题的真正根本原因。

在您的情况下,班级名称不正确。在构建JAR时,类名应为classes.utilities.arrayExtraInfo,否则您应该删除JAR中的/classes文件夹。


无关具体问题:请阅读Java Naming Conventions。类名应该以大写字母开头。