无法在嵌入式Jetty服务器中加载JSTL taglib [英] cannot load JSTL taglib within embedded Jetty server

查看:123
本文介绍了无法在嵌入式Jetty服务器中加载JSTL taglib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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


org.apache.jasper.JasperException:/index.jsp(1,63)PWC6188:绝对uri: http://java.sun.com/jsp/jstl/core 使用此应用程序部署

我在类路径上有以下jar

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

  • 码头-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

  • 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

M y web.xml如下所示:

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>

我的代码如下所示:

<%@ 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服务器:

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

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

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

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

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

推荐答案

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

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

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

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

这篇关于无法在嵌入式Jetty服务器中加载JSTL taglib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆