代码之家  ›  专栏  ›  技术社区  ›  Lior Cohen

Jetty 7 Hightide Distribution,支持jsp和jstl

  •  7
  • Lior Cohen  · 技术社区  · 16 年前

    我一直在与jetty 7及其对jsp和jstl的支持作斗争。

    我的JSP文件:

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    
    <head>
      <title>blah</title>
    </head>
    <body>
      <table id="data">
        <tr class="columns">
          <td>Hour</td>
          <c:forEach var="campaign" items="${campaigns}">
            <td>${campaign}</td>            
          </c:forEach>
        </tr>
    
        <c:forEach var="hour" items="${results}">
          <tr>
            <td class="hour">${hour.key}</td>
            <c:forEach var="campaign" items="${campaigns}">
              <td>${hour[campaign]}</td>
            </c:forEach>            
          </tr>     
         </c:forEach>
      </table>  
    </body>
    </html>
    

    上面的jsp部分按预期工作。然而,jstl没有。活动和结果变量是由servlet设置的请求属性。

    我得到以下错误:

    WARN: ... compiler.TagLibraryInfoImpl: Unknown element (deferred-value) in attribute
    WARN: ... compiler.TagLibraryInfoImpl: Unknown element (deferred-value) in attribute
    WARN: ... compiler.TagLibraryInfoImpl: Unknown element (deferred-value) in attribute
    ERROR: ... javax.servlet.ServletException: java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
    
    • 我没有将任何jar文件打包到部署到jetty的.war文件中。
    • 我使用的jetty版本是:jetty-hightide-7.0.1.v20091125

    类路径:

    /usr/local/jetty/lib/jetty-xml-7.0.1.v20091125.jar:/usr/local/jetty/lib/servlet-api-2.5.jar:/usr/local/jetty/lib/jetty-http-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-continuation-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-server-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-security-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-servlet-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-webapp-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-deploy-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-servlets-7.0.1.v20091125.jar:/usr/local/jetty/lib/jsp/ant-1.6.5.jar:/usr/local/jetty/lib/jsp/core-3.1.1.jar:/usr/local/jetty/lib/jsp/jetty-jsp-2.1-7.0.1.v20091125.jar:/usr/local/jetty/lib/jsp/jsp-2.1-glassfish-9.1.1.B60.25.p2.jar:/usr/local/jetty/lib/jsp/jsp-api-2.1-glassfish-9.1.1.B60.25.p2.jar:/usr/local/jetty/resources:/usr/local/jetty/lib/jetty-util-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-io-7.0.1.v20091125.jar
    

    任何帮助都将不胜感激。

    提前谢谢你,

    Lior。

    5 回复  |  直到 14 年前
        1
  •  2
  •   BalusC    16 年前
    java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
    

    此异常基本上意味着在运行时类路径中找不到所述方法,而在类或其依赖项之一的CompileTime类路径中可以找到该方法。

    这个 method 是在jsp 2.1中引入的,它与servlet2.5密切相关。由于jetty 7应该支持servlet 2.5,因此这里并不可疑,唯一的原因可能是 web.xml 声明为Servlet2.4或更低版本,而不是Servlet2.5。所以,要解决这个问题,您需要声明 小精灵 至少作为Servlet2.5。这个 <web-app> 标记应如下所示:

    <web-app 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="YourWebAppID"
        version="2.5">
    

    如果这不能解决问题,那么另一个原因是 /WEB-INF/lib 或者更糟的是 /JRE/lib /JRE/lib/ext 与包含旧的ServletAPI版本的AppServer特定库混淆。例如。 servlet-api.jar 来自Tomcat或 j2ee.jar javaee.jar 来自Glassfish,等等。您需要清除不属于那里的任何库中的类路径文件夹,因为它们在类加载中具有优先权,并且将覆盖appserver自己的库。appserver特定的库属于所讨论的appserver,而不是webapp或jre。


    也就是说,除了实际问题之外, @page 属性 language="java" contentType="text/html; charset=utf-8" 都是多余的。这个 language 已经默认为Java和 contentType 已经默认为 text/html 以及 charset 将已设置为 UTF-8 如果你设置 pageEncoding="UTF-8" . 因此,以下内容已经足够了:

    <%@page pageEncoding="UTF-8" %>
    
        2
  •  7
  •   bmargulies    16 年前

    对于8号码头,情况有点不同,以防这对任何人都有帮助。

    对于jstl 1.2,相当令人惊讶的是,taglib必须是:

    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    

    JSTL 1.2来自(Mavenishly):

     <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
     </dependency>
    

    我无法解释为什么url缺少“jsp”,但它是这样工作的。

        3
  •  4
  •   Community Mohan Dere    9 年前

    TSK…我无权评论。我使用7.1.6号码头,答案由 bmargulies 作品。

    基本上,从

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    

    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    

    使Taglibs在7号码头工作。

    尼森

        4
  •  4
  •   Steve    14 年前

    为什么 http://java.sun.com/jsp/jstl/core 不工作是因为JETY(Org.Apache .Jasp.GalsFiels:jar:2.2.2.xxx)所使用的JaspJSP解析器中的代码假定URI是Stururi(见TldScanner .java),它不会在TabLIB位置缓存中放置任何URI。我不知道为什么代码中有这个假设,但它是。对我来说好像是个虫子。

        5
  •  1
  •   Toilal    14 年前

    给小费史蒂夫!这个bug似乎仍然存在,这里有一个在jetty初始化时运行的解决方案。它给了我一个小把戏。

    import org.apache.jasper.runtime.TldScanner;
    import java.util.Set;
    
    Field field = TldScanner.class.getDeclaredField("systemUris");
    field.setAccessible(true);
    ((Set<?>)field.get(null)).clear();
    field.setAccessible(false);
    
    推荐文章