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

发布于 2024-08-19 05:56:46 字数 1782 浏览 2 评论 0 原文

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

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

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

上有以下 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 服务器?

I am writing a web application that runs within an embedded Jetty instance.

When I attempt to execute a JSTL statement, I receive the following exception:

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

I have the following jars on the classpath

  • 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

My web.xml looks like this:

<?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>

My code looks like this:

<%@ 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>

I started my embedded Jetty server like this:

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

I spent the past two days experimenting with various combinations of jar files, web.xml configurations, and tag library declarations, but to no avail.

How can I get an embedded Jetty server up and running with full JSTL support?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

咆哮 2024-08-26 05:56:46

jstl 标记库必须位于服务器 类路径上。您可以在启动服务器之前将类加载器添加到当前类加载器链中。这就是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 命令行参数中。

The jstl taglibs must be on server classpath. You can add a classloader to current classloader chain before start the server. That's the principle used by start.jar when it start a jetty server.

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();

You should also add it to java start command line argument.

你没皮卡萌 2024-08-26 05:56:46

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

指定 7.1.4.v20100610 对我有帮助。

Jetty 8.0, which has pushed as the default when you use jetty:run, has servlet API 3.0. As of that version of the standard, JSTL standard is supposed to be included, and these taglibs cannot be in the webapp classpath, only the standard classpath. However, 8.0.0.M0 forgot to include them.

Specifying 7.1.4.v20100610 helped for me.

梓梦 2024-08-26 05:56:46
  • jstl-1.2.jar
  • 标准-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 文件。

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

This collides. Remove the standard-1.1.2.jar. You should use standard-1.1.2.jar only with jstl-1.1.2.jar. Since JSTL 1.2 the standard JAR has been merged into JSTL JAR, resulting in a single jstl-1.2.jar file.

做个ˇ局外人 2024-08-26 05:56:46

@德鲁
谢谢德鲁。它有效。我一直在谷歌上搜索这个并最终来到这里。我的错误是:
我正在使用

                 <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 依赖项,并将其删除。

@Drew
Thanks Drew. It works.I had been googling for this and end up here.What my mistake was :
I was using

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

I changed it from above to

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

and it got working. Also I was using jstls dependency which I removed.

七七 2024-08-26 05:56:46

我在 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)中,我的 JAR“org.apache.taglibs.standard.glassfish-1.2.0.v2011120803.jar”上有标准 TLD,理论上,使用以下模式作为 ContainerIncludeJarPattern 的值就足够了:

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

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

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

I got the same problem on Jetty 7,
I solved it by enabling Jetty to search for TLD:

I did it by setting an attribute on the context:

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();

Refer to http://wiki.eclipse.org/Jetty/Howto/Configure_JSP#Using_JSTL_Taglibs_for_Jetty_7.x_and_8.x
for further details.

On my project (using maven), I have standard TLDs are on the JAR "org.apache.taglibs.standard.glassfish-1.2.0.v2011120803.jar" and theoretically it would be enough to use as value for ContainerIncludeJarPattern the following pattern:

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

It actually works and it is a confirmation of where do jetty found the tag libs, but I've preferred to leave the previous pattern which I found on the wiki.eclipse.org page linked above.

It may be required to extend the pattern if you want to include custom tag libs.

葬シ愛 2024-08-26 05:56:46

我遇到了同样的问题,发现 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);
}

I had the same problem and found out that http://java.sun.com/jsp/jstl/core is regarded as the single system URI and all taglib definitions that try to define it are ignored (but when referenced, an error occurs anyway).

I used the following before starting the Jetty and now it works:

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);
}
北方的韩爷 2024-08-26 05:56:46

两步:

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中添加follow属性

context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/org.apache.taglibs.taglibs-standard-impl-.*\\.jar$");

Two step:

1)add annotation support for the server

//Enable parsing of jndi-related parts of web.xml and jetty-env.xml, #server is

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) add the follow attribute to the WebAppContext

context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/org.apache.taglibs.taglibs-standard-impl-.*\\.jar$");
蓝天白云 2024-08-26 05:56:46

在 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,这是上面给出的建议。

In your web.xml, try changing "h77p://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" to start with "http://" and see if that fixes the error.

However, that may not be the underlying cause, since I had that same error when using jetty-maven-plugin and JSTL taglib header in my JSP:

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

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

I'm using an out-of-the-box Spring MVC template from SpringSource Tool Suite, so am not sure why the Maven plugin for Jetty chokes on it.

<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>

And only javax.servlet:jstl:1.2 is listed in my POM's dependencies, since it now obsoletes taglibs:standard:1.1.2, which was a suggestion given above.

悲喜皆因你 2024-08-26 05:56:46

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

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 名称。

I also had the same problems. I fixed it by adding the below code:

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

Maybe you can try it. Please replace TLD_JAR_NAMES with your real TLD Jar names.

紫罗兰の梦幻 2024-08-26 05:56:46

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

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

我正在使用 jetty-runner 8。

By adding the following code I got rid of the problem:

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

I am using jetty-runner 8.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文