在/var/lib/tomcat6/webapps/ROOT我有以下结构=>
/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 =>
<?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 =>
<?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>
但是我得到的只是=>
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吗?
web.xml
org.apache.jasper.JasperException:无法加载或实例化TagExtraInfo类:Utility.arrayExtraInfo
这只是意味着在幕后
TagExtraInfo tag = (TagExtraInfo) Class.forName("utilities.arrayExtraInfo").newInstance();
失败了。
也就是说,该类不在类路径中,或者没有默认的无参数构造函数。但是,真正的根本原因应该出现在堆栈跟踪中。在堆栈跟踪中进一步阅读,最底部是问题的真正根本原因。
在您的情况下,类名不正确。在构造JAR时,类名称应该为,classes.utilities.arrayExtraInfo或者应该摆脱/classesJAR 中的文件夹。
classes.utilities.arrayExtraInfo
/classes
与 具体问题 无关 :请阅读Java命名约定。类名应以大写开头。