2016-07-23 86 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,但有些甚至不足以自行工作。这是奇怪的行为,并且我没有任何意义.. –

相关问题