当我尝试在我的 web 应用程序中使用自定义标记库时,它无法在 OS X(或 Windows)上使用 Eclipse 和 Run Jetty Run。当我对文件进行 WAR 并在运行 apache-tomcat-6.0.20 的 linux 服务器上运行它们时,没有问题。我在两种环境中都使用 3rd 方自定义标记库而没有问题。
org.apache.jasper.JasperException: PWC6033: Unable to compile class for JSP
PWC6197: An error occurred at line: 6 in the jsp file: /temp.jsp
PWC6199: Generated servlet error:
com.test cannot be resolved to a type
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:107)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:280)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:350)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:411)
...
自定义 taglib 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>2.0</jsp-version>
<short-name>test</short-name>
<uri>http://test.com/test.tld</uri>
<description>Test</description>
<tag>
<name>custom</name>
<tag-class>com.test.CustomTag</tag-class>
<body-content>empty</body-content>
<description>Custom tag</description>
</tag>
</taglib>
和标签处理程序
package com.test;
import javax.servlet.jsp.tagext.TagSupport;
public class CustomTag extends TagSupport {
private static final long serialVersionUID = 1L;
}
最后是 temp.jsp
<%@ taglib uri="http://test.com/test.tld" prefix="test" %>
Hi
<test:custom/>
我认为我的 taglib 定义/配置是正确的,因为整个事情在部署到 tomcat 时都可以工作,但是我整天都在尝试使这项工作在 Jetty 中无济于事。