有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法在嵌入式Jetty服务器中加载JSTL标记库

我正在编写一个在嵌入式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

我在类路径上有以下罐子

  • 蚂蚁-1.6.5。罐子
  • 蚂蚁-1.7.1。罐子
  • ant-launcher-1.7.1。罐子
  • 核心-3.1.1。罐子
  • 码头-6.1.22。罐子
  • jetty-util-6.1.22。罐子
  • jsp-2.1-6.1.14。罐子
  • jsp-api-2.1。罐子
  • jstl-1.2。罐子
  • servlet-api-2.5-20081211。罐子
  • servlet-api-2.5-6.1.14。罐子
  • 标准-1.1.2。罐子

我的网络。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配置和标记库声明,但没有用

如何让嵌入式Jetty服务器在完全支持JSTL的情况下启动并运行


共 (4) 个答案

  1. # 1 楼答案

    我也遇到了同样的问题,并发现http://java.sun.com/jsp/jstl/core被视为单个系统URI,所有试图定义它的taglib定义都被忽略(但当被引用时,仍然会发生错误)

    在启动码头之前,我使用了以下方法,现在它可以工作了:

    try {
        Field f = TldScanner.class.getDeclaredField("systemUris");
        f.setAccessible(true);
        ((Set)f.get(null)).clear();
    } catch (Exception e) {
        throw new RuntimeException("Could not clear TLD system uris.",e);
    }
    
  2. # 2 楼答案

    Jetty 8.0是servlet API 3.0,在使用Jetty:run时作为默认版本推送。在该版本的标准中,应该包括JSTL标准,这些标记库不能在webapp类路径中,只能在标准类路径中。然而,8.0.0。M0忘了包括它们

    规定7.1.4。v20100610对我有帮助

  3. # 3 楼答案

    @Drew 谢谢Drew。它起作用了。我一直在谷歌上搜索这个,最后来到了这里。我的错误是: 我在用

                     <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>jstl</artifactId>
                         <version>1.1.2</version>
                         <scope>provided</scope>
                    </dependency>
    

    我把它从上面改成了

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

    它开始工作了。我还使用了我删除的jstls依赖项

  4. # 4 楼答案

    • jstl-1.2.jar
    • standard-1.1.2.jar

    这是相互冲突的。移除standard-1.1.2.jar。你应该只把standard-1.1.2.jarjstl-1.1.2.jar一起使用。自JSTL 1.2以来,标准JAR已经被合并到JSTL JAR中,形成了一个jstl-1.2.jar文件