15

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

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

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

我在类路径上有以下罐子

  • 蚂蚁1.6.5.jar
  • 蚂蚁1.7.1.jar
  • ant-launcher-1.7.1.jar
  • 核心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
  • 标准 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 服务器?

4

10 回答 10

8

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

指定 7.1.4.v20100610 对我有帮助。

于 2010-07-03T18:13:09.123 回答
8

jstl taglibs 必须在服务器类路径上。您可以在启动服务器之前将类加载器添加到当前的类加载器链。这就是 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();

您还应该将它添加到 java start 命令行参数。

于 2012-10-11T23:29:27.880 回答
5
  • jstl-1.2.jar
  • 标准 1.1.2.jar

这发生了冲突。删除standard-1.1.2.jar. 你应该standard-1.1.2.jar 使用with jstl-1.1.2.jar。自 JSTL 1.2 起,标准 JAR 已合并到 JSTL JAR 中,形成一个jstl-1.2.jar文件。

于 2010-01-28T11:56:52.497 回答
3

@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 依赖项。

于 2010-09-03T19:57:15.700 回答
3

我在 Jetty 7 上遇到了同样的问题,我通过启用 Jetty 搜索 TLD 来解决它:

我通过在上下文中设置一个属性来做到这一点:

Server server = new Server(80);  
WebAppContext context = new WebAppContext("pig-1.0-SNAPSHOT.war","/");
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", 
    ".*/.*jsp-api-[^/]*\\.jar$|.*/.*jsp-[^/]*\\.jar$|.*/.*taglibs[^/]*\\.jar$");
server.addHandler(context);
server.start();

有关详细信息,请参阅http://wiki.eclipse.org/Jetty/Howto/Configure_JSP#Using_JSTL_Taglibs_for_Jetty_7.x_and_8.x

在我的项目(使用 maven)中,标准 TLD 位于 JAR“org.apache.taglibs.standard.glassfish-1.2.0.v2011120803.jar”上,理论上它足以用作 ContainerIncludeJarPattern 的值以下模式:

".*/org\\.apache\\.taglibs\\.standard\\.glassfish-1\\.2\\.0\\.v201112081803\\.jar"

它确实有效,它确认了码头在哪里找到了标签库,但我更愿意保留我在上面链接的 wiki.eclipse.org 页面上找到的先前模式。

如果您想包含自定义标签库,可能需要扩展模式。

于 2013-09-20T16:22:37.027 回答
2

我遇到了同样的问题,发现它http://java.sun.com/jsp/jstl/core被视为单个系统 URI,并且所有尝试定义它的 taglib 定义都被忽略(但是在引用时,无论如何都会发生错误)。

我在启动 Jetty 之前使用了以下内容,现在它可以工作了:

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);
}
于 2014-06-05T09:10:06.533 回答
1

两步:</p>

1)增加服务端注解支持

//启用web.xml和jetty-env.xml中jndi相关部分的解析,#server为

org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");

2)将跟随属性添加到WebAppContext

context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/org.apache.taglibs.taglibs-standard-impl-.*\\.jar$");
于 2016-08-11T06:10:55.027 回答
0

在您的 web.xml 中,尝试将“h77p://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”更改为以“http://”开头,看看是否可以修复错误。

但是,这可能不是根本原因,因为在我的 JSP 中使用 jetty-maven-plugin 和 JSTL taglib 标头时遇到了同样的错误:

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

PWC6188:绝对 uri: http: //java.sun.com/jsp/jstl/core 无法在 web.xml 或随此应用程序部署的 jar 文件中解析

我正在使用 SpringSource Tool Suite 中的开箱即用 Spring MVC 模板,所以我不确定为什么 Jetty 的 Maven 插件会阻塞它。

<build>
   <plugins>
      <plugin>
         <groupId>org.mortbay.jetty</groupId>
         <artifactId>jetty-maven-plugin</artifactId>
      </plugin>
   </plugins>
</build>
<repositories>
     <repository>
       <id>maven2-repository.dev.java.net</id>
       <name>Java.net Repository for Maven</name>
       <url>http://download.java.net/maven/2/</url>
       <layout>default</layout>
     </repository>
</repositories>

我的 POM 的依赖项中只列出了 javax.servlet:jstl:1.2,因为它现在已经废弃了 taglibs:standard:1.1.2,这是上面给出的建议。

于 2010-04-17T01:18:56.280 回答
0

通过添加以下代码,我摆脱了这个问题:

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>jasper</artifactId>
    <version>6.0.29</version>
</dependency>

我正在使用jetty-runner 8。

于 2014-07-23T16:29:29.370 回答
0

我也有同样的问题。我通过添加以下代码来修复它:

public static final String[] TLD_JAR_NAMES = new String[]{"sitemesh", "spring-webmvc", "shiro-web", "springside-core"};
...
JettyFactory.setTldJarNames(server, TLD_JAR_NAMES);

也许你可以试试。请将 TLD_JAR_NAMES 替换为您的真实 TLD Jar 名称。

于 2013-06-16T04:32:12.400 回答