无法在嵌入式Jetty服务器中加载JSTL taglib

15 java jstl jetty taglib embedded-jetty

我正在编写一个在嵌入式Jetty实例中运行的Web应用程序.

当我尝试执行JSTL语句时,收到以下异常:

org.apache.jasper.JasperException:/index.jsp(1,63)PWC6188:绝对uri:http://java.sun.com/jsp/jstl/core无法在web.xml或jar文件中解析使用此应用程序部署

我在classpath上有以下jar

  • ANT-1.6.5.jar
  • ANT-1.7.1.jar
  • 蚂蚁发射-1.7.1.jar
  • 核心3.1.1.jar
  • 码头,6.1.22.jar
  • 码头-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
  • 标准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>
Run Code Online (Sandbox Code Playgroud)

我的代码看起来像这样:

<%@ 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>
Run Code Online (Sandbox Code Playgroud)

我开始使用这样的嵌入式Jetty服务器:

Server server = new Server(80);  
WebAppContext context = new WebAppContext("pig-1.0-SNAPSHOT.war","/");
server.addHandler(context);
server.start();
Run Code Online (Sandbox Code Playgroud)

我花了两天时间尝试各种jar文件组合,web.xml配置和标签库声明,但无济于事.

如何在完整的JSTL支持下启动并运行嵌入式Jetty服务器?

bma*_*ies 8

Jetty 8.0,在使用jetty:run时作为默认值推送,具有servlet API 3.0.从该版本的标准开始,应该包含JSTL标准,并且这些标记库不能在webapp类路径中,只能在标准类路径中.但是,8.0.0.M0忘了包含它们.

指定7.1.4.v20100610对我有帮助.


小智 8

jstl taglib必须位于服务器类路径上.您可以在启动服务器之前将类加载器添加到当前的类加载器链.这是start.jar启动jetty服务器时使用的原则.

ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
URL urlTaglibs = new File(PATH_TO_TAGLIBS).toURI().toURL();
URLClassLoader newClassLoader = new URLClassLoader(new URL[]{urlTaglibs},currentClassLoader);
Thread.currentThread().setContextClassLoader(newClassLoader);

server.start();
Run Code Online (Sandbox Code Playgroud)

您还应该将其添加到java start命令行参数中.


Bal*_*usC 5

  • JSTL-1.2.jar
  • 标准1.1.2.jar

这碰撞了.删除standard-1.1.2.jar.你应该standard-1.1.2.jar 使用jstl-1.1.2.jar.从JSTL 1.2开始,标准JAR已合并到JSTL JAR中,从而生成单个jstl-1.2.jar文件.