我一直在努力尝试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;
类路径:
/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
任何帮助将不胜感激。
提前致谢,
骗子
java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
java.lang.AbstractMethodError:
javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
此异常基本上意味着,在类或其依赖项之一的编译时类路径中可以使用运行时类路径中找不到的方法。
JSP 2.1中引入了该方法,该方法与Servlet 2.5紧密结合。由于Jetty 7应该支持Servlet 2.5,因此在这里不是可疑的,唯一的原因可能web.xml是声明为Servlet 2.4或更低版本而不是Servlet 2.5。因此,要解决此特定问题,您需要web.xml至少声明Servlet 2.5。该<web- app>标签应该是这样的:
web.xml
<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堆满了含有较旧的Servlet API版本特定应用程序服务器的库。例如,servlet-api.jar从Tomcat或j2ee.jar 或javaee.jar从Glassfish的,等等。您需要从任何不属于该库的库中清理这些类路径文件夹,因为它们在类加载中具有优先权,并且将覆盖应用服务器自己的库。特定于Appserver的库属于所讨论的appserver,而不属于webapp或JRE。
/WEB- INF/lib
/JRE/lib
/JRE/lib/ext
servlet-api.jar
j2ee.jar
javaee.jar
话虽如此,除了实际的问题之外,所有@page属性language="java" contentType="text/html; charset=utf-8"都是多余的。在language已经默认为爪哇和contentType已经默认text/html和charset就已经被设置到UTF-8如果设置pageEncoding="UTF-8"。因此,以下内容已足够:
@page
language="java" contentType="text/html; charset=utf-8"
language
contentType
text/html
charset
UTF-8
pageEncoding="UTF-8"
<%@page pageEncoding="UTF-8" %>