jetty 8.x, 9.x無法載入jstl的PWC6188問題,jstlpwc6188

來源:互聯網
上載者:User

jetty 8.x, 9.x無法載入jstl的PWC6188問題,jstlpwc6188

參考:

cannot load JSTL taglib within embedded Jetty server:http://stackoverflow.com/questions/2151075/cannot-load-jstl-taglib-within-embedded-jetty-server

How do you get embedded Jetty 9 to successfully resolve the JSTL URI?: http://stackoverflow.com/questions/17685330/how-do-you-get-embedded-jetty-9-to-successfully-resolve-the-jstl-uri;

JSTL核心標籤使用:http://www.cnblogs.com/lihuiyy/archive/2012/02/24/2366806.html

JSP運算式語言:http://blog.csdn.net/csuliky/article/details/2452207
Using Spring3.2 MVC with embedded jetty9:http://stackoverflow.com/questions/19169377/using-spring3-2-mvc-with-embedded-jetty9

1. 簡述

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" isELIgnored="false" %> 

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

上述異常在tomcat等地方只需要在頁面上添加相應的語句即可解決。但是這裡使用的嵌入式Jetty時還是會出現上述問題。

在jetty啟動前添加上面的代碼。問題原因是Jetty無法載入JSTL類庫。這是一個bug

2. Jetty依賴

<dependency>

    <groupId>org.eclipse.jetty</groupId>

    <artifactId>jetty-webapp</artifactId>

    <version>9.0.7.v20131107</version>

    <scope>test</scope>

   </dependency>

   <dependency>

    <groupId>org.eclipse.jetty</groupId>

    <artifactId>jetty-servlet</artifactId>

    <version>9.0.7.v20131107</version>

    <scope>test</scope>

   </dependency>

   <dependency>

    <groupId>org.eclipse.jetty</groupId>

    <artifactId>jetty-jsp</artifactId>

    <version>9.0.7.v20131107</version>

   </dependency>

3. 運行代碼

public class JettyServer {

public static void main(String[] args) throws Exception {

  System.setProperty("DWPROJECTNO", "resource");

  System.setProperty("DWENV", "dev");

  startJettyServer(80, "/");

}

/**

  * 建立用於正常運行調試的Jetty Server, 以src/main/webapp為Web應用目錄.

  *

  * @throws Exception

  */

public static void startJettyServer(int port, String contextPath) throws Exception {

  /* fix jetty8.x, jetty 9.x can't load jstl library */

  Field f = TldScanner.class.getDeclaredField("systemUris");

  f.setAccessible(true);

  ((Set<?>) f.get(null)).clear();

  f.setAccessible(false);

  Server server = new Server(port);

  WebAppContext webContext = new WebAppContext("src/main/webapp", contextPath);

  webContext.setClassLoader(Thread.currentThread().getContextClassLoader());

  webContext.setDefaultsDescriptor("src/test/resources/jetty-webdefault.xml");

  server.setHandler(webContext);

  server.setStopAtShutdown(true);

  server.start();

  server.join();

}

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.