为什么jsp页面有foreach标签的那块东西显示不出来呢?
全体树立 2009-06-03 01:50:50 页面中用foreach标签嵌套的那个表格怎么都显示不出来呢?请路过的高手帮我看看。
页面代码
<%@ page language="java" import="java.util.*,com.company.dao.impl.*,com.company.entity.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="tag"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>商品列表页面</title>
</head>
<body>
<table width="974" height="150" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><jsp:include page="top.jsp" /></td>
</tr>
<tr>
<td width="138"><jsp:include page="left.jsp" /></td>
<td width="626">
12315635<table width="626" height="64" border="1" align="center" cellpadding="0" cellspacing="0">
<!-- 产品展示开始 -->
<jsp:useBean id="getProduct" class="com.company.dao.impl.ProductDaoImpl" />
<!-- 从数据库中取出产品信息赋给products变量,作用域:session -->
<tag:set var="products" value="${getProducts.products}" scope="session" />
<!-- 迭代循环,依次从foods变量中取出餐品,在页面中用EL显示该餐品各项信息 -->
<tag:forEach var="currentproduct" items="${sessionScope.products}" >
<tr>
<td width="99" rowspan="2"><a
href="detailProduct.jsp?productID=${currentproduct.productID}"
target=_blank><IMG height=50 alt=点击图片查看内容
src="images/${currentproduct.picture}" width=50 border=0></A></td>
<td width="44" rowspan="2">0</td>
<td width="123" bgcolor="#CCCCCC"> 产品名称</td>
<td width="127"><a
href="detailProduct.jsp?foodID=${currentproduct.productID}"
target=_blank><STRONG>${currentproduct.name}</STRONG></A></td>
<td width="100" bgcolor="#CCCCCC"> 产品品牌</td>
<td width="119"><a
href="detailProduct.jsp?foodID=${currentproduct.productID}"
target=_blank><STRONG>${currentproduct.brand}</STRONG></A></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"> 产品型号</td>
<td><a
href="detailProduct.jsp?foodID=${currentproduct.productID}"
target=_blank><STRONG>${currentproduct.model}</STRONG></A></td>
<td bgcolor="#CCCCCC"> 产品价格</td>
<td><a
href="detailProduct.jsp?foodID=${currentproduct.productID}"
target=_blank><STRONG>${currentproduct.price}</STRONG></A></td>
</tr>
</tag:forEach>
</table></td>
</tr>
</table>
</body>
</html>
方法代码
public List findAllProduct() {
List list = (List) new ArrayList();
String sql = "SELECT * from PRODUCT";
// 获取餐品列表
try {
con = DBConnection.getConnection();
ps = con.prepareStatement(sql);
ResultSet results = ps.executeQuery();
// 读取行数据
while (results.next()) {
Product product = new Product();
product.setProductID(results.getInt("productID"));
product.setSerialNumber(results.getString("serialNumber"));
product.setName(results.getString("name"));
product.setBrand(results.getString("brand"));
product.setModel(results.getString("model"));
product.setPrice(results.getString("pirce"));
product.setPicture(results.getString("picture"));
product.setDescription(results.getString("description"));
list.add(product);
}
}
// 处理数据库异常
catch (SQLException e) {
e.printStackTrace();
}
// 释放资源
finally {
DBConnection.closeResultSet(results);
DBConnection.closePreparedStatement(ps);
DBConnection.closeConnection(con);
}
return list;
}