这是在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
@微小它不会改变任何东西。 –