c:forEach在tomcat 7中不工作 [英] c:forEach not working in tomcat 7

查看:83
本文介绍了c:forEach在tomcat 7中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 c:forEach 标签创建了简单页面.它在tomcat 6中工作.但是not working tomcat 7.使用JSF 2.0开发了简单的Web应用程序.

I created simple page using c:forEach tag. Its working in tomcat 6. But not working tomcat 7. Developed simple web application using JSF 2.0.

我在tomcat 6中运行我的代码. 我部署在tomcat 7中.它无法正常工作. c:forEach标签结果未显示.

I run my code in tomcat 6. its working. I deployed in tomcat 7. Its not working. c:forEach tag result not appearing.

welcomeJSF.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>

faces-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>

SimpleDemo.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;
}  }       

UserBean.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;
}

}

帮帮我, 预先感谢.

推荐答案

删除standard.jar.它来自JSTL 1.1,与您的JSTL 1.2冲突.

Remove standard.jar. It's from JSTL 1.1 and conflicting with your JSTL 1.2.

这篇关于c:forEach在tomcat 7中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆