程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> jetty 8.x, 9.x無法加載jstl的PWC6188問題,jstlpwc6188

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

編輯:JAVA綜合教程

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

}

}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved