3

当我尝试在我的 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 中无济于事。

4

3 回答 3

1

太烦了!!!!我希望上帝,有人发现了这一点,它可以节省我浪费在试图找出解决方案的所有时间。我相信这是 Jetty 的问题。

我还在 com 包中有一个类 Test 。因此,无论出于何种原因,Jetty 都会去寻找 com.test.CustomTag 并最终寻找可能在 com.Test 内部的内部类?无论如何,将 CustomTag 移动到另一个包(或移动或重命名 com.Test)解决了这个问题。

于 2010-07-10T02:02:39.230 回答
1

得到了解决方案。虽然我编译时我的 Eclipse 没有显示错误。Jetty 运行时,没有找到我添加的新类属性。由于 Maven 尚未生成它。

我运行了这两个命令,之后一切都很好。1. mvn clean 2. mvn install -DskipTests

于 2014-04-17T14:39:19.687 回答
0

我有一些同样的问题。码头但自定义标记文件(无标记库)

由于 Tyler 的帖子(2010 年 7 月 10 日 0:45),我将在这里放弃。我可能会向码头人群陈述我的情况。我无法将我的自定义标签移动到另一个包,因为它是一个标签文件并且没有声明一个包。

在 Eclipse 中它工作正常。所有 Junit 测试都以绿色运行。'mvn test' 因 PWC6033 失败,但没有进一步的详细信息。我只能猜到标签文件在部署到服务器时显然运行正确。

如果jetty / maven没有正确解决导入问题,那么对我来说这听起来像是一个错误。

为了完整起见,这是我的标记文件,位于/WEB-INF/tags/ognl.tag

<%@tag import="de.mypackage.WebUtils"
%><%@tag body-content="empty"
%><%@attribute name="value" required="true"
%><%=WebUtils.ognl(request, value)%>

WebUtils 采用 HttpServletRequest 以获取属性值和另一个参数,该参数确实将一些内容打印到标准输出中。

于 2012-09-11T21:00:22.403 回答