2016-07-23 37 views
0

這是在pom.xml中爲什麼forEach標籤不能與Tomcat一起使用,但Jetty一切正常?

<dependency> 
    <groupId>com.sun.faces</groupId> 
    <artifactId>jsf-api</artifactId> 
    <version>2.2.13</version> 
</dependency> 
<dependency> 
    <groupId>com.sun.faces</groupId> 
    <artifactId>jsf-impl</artifactId> 
    <version>2.2.13</version> 
</dependency> 

我有依賴和碼頭插件使用:

<plugin> 
    <groupId>org.eclipse.jetty</groupId> 
    <artifactId>jetty-maven-plugin</artifactId> 
    <version>9.2.1.v20140609</version> 
</plugin> 

和Tomcat的我用的是:8.5.4。

這是我的觀點:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://xmlns.jcp.org/jsf/html" 
     xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"> 
<h:head> 
    <title>Student List</title> 
</h:head> 
<h:body> 
    <c:forEach items="#{studentBean.studentList}" 
       var="student"> 
     #{student.fullname} 
     <br/> 
    </c:forEach> 
</h:body> 
</html> 

當我運行這個應用程序是這樣的:

mvn clean install 
mvn jetty:start 

和訪問本地主機:8080,我會在清單上看到我的瀏覽器就好了。

Koray Tugay 
Mick Jagger 

現在,如果我複製創建.war文件,並將其部署到Tomcat,我會看到:

type Exception report 
message javax/servlet/jsp/jstl/core/LoopTagStatus 
description The server encountered an internal error that prevented it from fulfilling this request. 
exception 
javax.servlet.ServletException: javax/servlet/jsp/jstl/core/LoopTagStatus 
javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) 
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
javax.faces.view.facelets.FaceletException: javax/servlet/jsp/jstl/core/LoopTagStatus 
com.sun.faces.facelets.tag.AbstractTagLibrary$UserComponentHandlerFactory.createHandler(AbstractTagLibrary.java:344) 
java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.LoopTagStatus 

(完整的堆棧跟蹤here ..)

現在你也許很想比如說Tomcat沒有附帶JSTL,你應該把它作爲依賴添加到你的pom.xml中!但是,在這一點上,我會問你:

爲什麼它可以與Jetty正常工作?

此外,當我經過JSF的IMPL-2.2.13.jar,這Maven的下載,我找到一個名爲文件:COM /陽光下JSTL-core.taglib /面/元/標籤庫。

而且在這個文件中,我看到這個標籤聲明:

<tag> 
    <description><![CDATA[ 
      The basic iteration tag, accepting many different 
      collection types and supporting subsetting and other 
      functionality 
     ]]></description> 
    <tag-name>forEach</tag-name> 
    <handler-class>com.sun.faces.facelets.tag.jstl.core.ForEachHandler</handler-class> 
    <attribute> 
     <description><![CDATA[ 
       Collection of items to iterate over. 
      ]]></description> 
     <name>items</name> 
     <required>false</required> 
     <type>java.lang.Object</type> 
    </attribute> 
</tag> 

而且,類com.sun.faces.facelets.tag.jstl.core.ForEachHandler已經包含在jsf- IMPL-2.2.13.jar。

所以我的理解是,c:forEach應該包含在JSF實現中。爲什麼Tomcat不喜歡這種情況?

如果我有這種依賴性:

<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>jstl</artifactId> 
    <version>1.2</version> 
</dependency> 
在pom.xml中

,在Tomcat的循環將循環高興地爲好。這是如何工作,或不工作?

+0

從頭開始清理和構建/(重新)部署應用程序。 – Tiny

+0

@微小它不會改變任何東西。 –

回答

1

com.sun.faces.facelets.tag.jstl.core.ForEachHandler通過其依賴項com.sun.faces.facelets.tag.jstl.core.JstlIterationStatus依賴於javax.servlet.jsp.jstl.core.LoopTagStatus

Tomcat不附帶它。因此所需的JSTL依賴。

Jetty顯然提供了自己的JSTL庫。所以你不需要通過webapp包含它。你應該至少標記它<scope>provided</scope>

+0

但我不明白的是,爲什麼它不包含在JSF jar中?如果JSF包含ForEachHandler,那麼它應該包含它的依賴關係嗎? –

+0

爲什麼要這樣?如果你走這條路線,你也會想知道爲什麼它不包括Servlet,JSP,CDI等,甚至是Java SE依賴項。這些只是環境應該已經提供的最低要求。無需在JSF庫中包含所有這些依賴關係。 「ForeachHandler」是必需的,因爲基於JSP的標籤在Facelets中不起作用。 – BalusC

+0

爲什麼包含ForEachHandler呢?因爲它已經存在於JSTL中,不是嗎?我會問這個問題是否執行了運行Servlets所需的類的一半。它不包括任何它們,但包括一些JSTL,但有些甚至不足以自行工作。這是奇怪的行爲,並且我沒有任何意義.. –

相關問題