我正在编写一个在嵌入式 Jetty 实例中运行的 Web 应用程序。
当我尝试执行 JSTL 语句时,收到以下异常:
org.apache.jasper.JasperException: /index.jsp(1,63) PWC6188: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
我在类路径上有以下 jar
- ant-1.6.5.jar
- ant-1.7.1.jar
- ant-launcher-1.7.1.jar
- core-3.1.1.jar
- jetty-6.1.22.jar
- jetty-util-6.1.22.jar
- jsp-2.1-6.1.14.jar
- jsp-api-2.1.jar
- jSTL-1.2.jar
- servlet-api-2.5-20081211.jar
- servlet-api-2.5-6.1.14.jar
- standard-1.1.2.jar
我的 web.xml 如下所示:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee h77p://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>test</display-name>
</web-app>
我的代码是这样的:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<h2>Hello World!</h2>
<%= new java.util.Date() %><br/>
${1+2}<br/>
<c:out var="${5+9}"/><br/>
</body>
</html>
我这样启动了我的嵌入式 Jetty 服务器:
Server server = new Server(80);
WebAppContext context = new WebAppContext("pig-1.0-SNAPSHOT.war","/");
server.addHandler(context);
server.start();
我在过去两天尝试了 jar 文件、web.xml 配置和标记库声明的各种组合,但无济于事。
如何在完全支持 JSTL 的情况下启动并运行嵌入式 Jetty 服务器?
最佳答案
当您使用 jetty:run 时默认推送的 Jetty 8.0 具有 servlet API 3.0。从那个版本的标准开始,应该包含 JSTL 标准,并且这些标签库不能在 webapp 类路径中,只能在标准类路径中。但是,8.0.0.M0 忘了包含它们。
指定 7.1.4.v20100610 对我有帮助。
关于java - 无法在嵌入式 Jetty 服务器中加载 JSTL taglib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2151075/