這是在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的循環將循環高興地爲好。這是如何工作,或不工作?
從頭開始清理和構建/(重新)部署應用程序。 – Tiny
@微小它不會改變任何東西。 –