我使用c:forEach标签创建了简单的页面。它在tomcat 6中工作。但是not working tomcat 7
。使用 JSF 2.0 开发简单的 Web 应用程序。
我在tomcat 6中运行我的代码。它的工作。我部署在tomcat 7中。它不工作。c:forEach 标记结果未出现。
欢迎JSF.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h:form id="forEachForm" binding="#{simpleDemo.initForm}">
<c:forEach items="#{simpleDemo.userBeanList}" var="userBean" varStatus="status">
<h:panelGrid columns="2" border="1">
<h:outputText value="#{userBean.userName}"/>
<h:outputText value="#{userBean.role}"/>
</h:panelGrid>
</c:forEach>
</h:form>
</body></html></f:view>
我用了下面的罐子
1. jsf-api.jar
2. jsf-impl.jar
3. jstl-1.2.jar
4. standard.jar
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/welcomeJSF.jsp</welcome-file>
</welcome-file-list>
</web-app>
面孔-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns
/javaee/web-facesconfig_2_0.xsd">
<managed-bean>
<managed-bean-name>simpleDemo</managed-bean-name>
<managed-bean-class>com.tomcat.foreach.SimpleDemo</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
简单演示.java
package com.tomcat.foreach;
import java.util.ArrayList;
import java.util.List;
import javax.faces.component.html.HtmlForm;
public class SimpleDemo
{
private HtmlForm initForm;
private List<UserBean> userBeanList = new ArrayList<UserBean>();
public HtmlForm getInitForm()
{
userBeanList.clear();
UserBean userBean = new UserBean();
userBean.setUserName("jack");
userBean.setRole("sample Role");
userBeanList.add(userBean);
userBean = new UserBean();
userBean.setUserName("adminuser");
userBean.setRole("Admin Role");
userBeanList.add(userBean);
userBean = new UserBean();
userBean.setUserName("Test User");
userBean.setRole("Test role");
userBeanList.add(userBean);
return initForm;
}
public void setInitForm(HtmlForm initForm){
this.initForm = initForm;
}
public List<UserBean> getUserBeanList(){
return userBeanList;
}
public void setUserBeanList(List<UserBean> userBeanList){
this.userBeanList = userBeanList;
} }
用户Bean.java
package com.tomcat.foreach;
public class UserBean
{
private String userName;
private String role;
public String getUserName(){
return userName;
}
public void setUserName(String userName){
this.userName = userName;
}
public String getRole(){
return role;
}
public void setRole(String role){
this.role = role;
}
}
帮助我,提前谢谢。