<%@page contentType="text/html;charset=gbk"%>
<%@page import="java.util.*" %>
<%@page import="com.sinly.entity.*"%>
<%@taglib  uri="http://java.sun.com/jsp/jstl/core"  prefix="c" %>
<%
Collection<Product> coll=(Collection<Product>)request.getSession(true).getAttribute("products");
%>
<html>
<h1><%=((Product)coll.iterator().next()).getProductId()%></h1>
<body>
<table bordercolor="red" border="2" width="70%">
<tr>
<td>商品名编号</td>
<td>商品名称</td>
<td>商品价格</td>
</tr>
<tr><td>1</td><td>测试</td><td>1000000</td>
<c:forEach   var="p"  items="${coll}">
<tr>
<td>1:${p.productId}</td>
<td>2:${p.productName}</td>
<td>3:${p.price}</td>
</tr>
</c:forEach>

</table>
</body>
</html>
其中<h1>标签可以拿到ID值,测试size()也有值
想问下,为什么下面的c标签取不到值
在线等答案!

解决方案 »

  1.   

    <c:forEach  var="p"  items="${coll}"> 应该是<c:forEach  var="p"  items="${products}"> 
    <tr> 
    <td>1:${p.productId} </td> 
    <td>2:${p.productName} </td> 
    <td>3:${p.price} </td> 
    </tr> 
      

  2.   

    <c:forEach  var="p"  items="${coll}"> 
    直接
    <c:forEach  var="p"  items="${products}"> 
      

  3.   

    <c:forEach  var="p"  items="${coll}"> 
    是从范围中取得
    你没有把coll放到Scope里,当然就取不到了
    <%
    Collection <Product> coll=(Collection <Product>)request.getSession(true).getAttribute("products");
    request.setAttribute("coll",coll);
    %> 
    这样试试