jsp 显示不了刚查询出来的结果

Alaska_Lee 2015-07-30 11:45:40

<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false"%>
<%-- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> --%>
<jsp:directive.page import="com.smoothlybelt.dao.ProductDao"/>
<jsp:directive.page import="com.smoothlybelt.been.Product"/>
<jsp:directive.page import="java.util.List"/>
<jsp:directive.page import="java.util.Iterator"/>

<%
List<Product> productList = ProductDao.listProducts();
Iterator<Product> it = productList.iterator();
while(it.hasNext()){
Product p = it.next();
System.out.println(p.getProductId());
System.out.println(p.getStoreId());
System.out.println(p.getSalesTotalVolume());
System.out.println(p.getProductEvalute());
}

request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
request.setAttribute("productList", productList);

%>

<html text-algin="center">

<form action="" method = get>
<table bgcolor = #cccccc cellspacing=1 cellpadding=5 width=100% >
<tr bgcolor=#dddddd>

<th>产品ID</th>
<th>商店ID</th>
<th>产品价格</th>
<th>产品状态</th>
<th>发布时间</th>
<th>产品总销量</th>
<th>最小免费金额</th>
</tr>
<c:forEach items="${productList} " var="product">
<tr bgcolor=#dddddd height=50>
<td>${product.productId}</td>
<td>${product.storeId}</td>
<td>${product.productPrise}</td>
<td>${product.productState}</td>
<td>${product.publishTime}</td>
<td>${product.salesTotalVolume}</td>
<td>${product.minFreeCost}</td>
</tr>
</c:forEach>
</table>
</form>

</html>


本人刚学java web,按书上写了个例子。
productList中可以明确是有结果的,while循环里面的结果也是可以打出来的,但是为什么最终页面表格里面显示不出数据?
...全文
271 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Alaska_Lee 2015-08-11
  • 打赏
  • 举报
回复
在9楼的基础上 终于找到原因了 <c:forEach items="${productList} " var="product"> 这句话{}后面留了一个空格. 诶 郁闷呢死了
菜鸟营新兵 2015-08-03
  • 打赏
  • 举报
回复
#9楼好像说对了
qq137510669 2015-08-03
  • 打赏
  • 举报
回复
你最上面的<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>被注释掉了,<c:foreach>标签是从这里取的,现在取不到了,当然就什么也不显示了。
Alaska_Lee 2015-08-01
  • 打赏
  • 举报
回复
引用 3 楼 wi496481 的回复:
你要取的值在这里面 productList 怎么跑到Product这去取了??
我是要遍历productList的每一项,当然要到Product里面取了
Alaska_Lee 2015-08-01
  • 打赏
  • 举报
回复
引用 5 楼 u012791859 的回复:
<c:foreach> items属性没取到值吧
这个写法不对吗?书上是这么写的啊!
Alaska_Lee 2015-08-01
  • 打赏
  • 举报
回复
引用 4 楼 u014431852 的回复:
product里面有没有get和set方法?
set get都有的
package com.smoothlybelt.been;

import java.sql.Time;

public class Product {
	private String productId;
	private String storeId;
	private Time publishTime;
	private int productType;
	private double minFreeCost;
	private int discountType;
	private String discount;
	private int productEvalute;
	private double productPrise;
	private int salesTotalVolume;
	private int salesMonthlyVolume;
	private int productState;
	public String getProductId() {
		return productId;
	}
	public void setProductId(String productId) {
		this.productId = productId;
	}
	public String getStoreId() {
		return storeId;
	}
	public void setStoreId(String storeId) {
		this.storeId = storeId;
	}
	public Time getPublishTime() {
		return publishTime;
	}
	public void setPublishTime(Time publishTime) {
		this.publishTime = publishTime;
	}
	public int getProductType() {
		return productType;
	}
	public void setProductType(int productType) {
		this.productType = productType;
	}
	public double getMinFreeCost() {
		return minFreeCost;
	}
	public void setMinFreeCost(double minFreeCost) {
		this.minFreeCost = minFreeCost;
	}
	public int getDiscountType() {
		return discountType;
	}
	public void setDiscountType(int discountType) {
		this.discountType = discountType;
	}
	public String getDiscount() {
		return discount;
	}
	public void setDiscount(String discount) {
		this.discount = discount;
	}
	public int getProductEvalute() {
		return productEvalute;
	}
	public void setProductEvalute(int productEvalute) {
		this.productEvalute = productEvalute;
	}
	public double getProductPrise() {
		return productPrise;
	}
	public void setProductPrise(double productPrise) {
		this.productPrise = productPrise;
	}
	public int getSalesTotalVolume() {
		return salesTotalVolume;
	}
	public void setSalesTotalVolume(int salesTotalVolume) {
		this.salesTotalVolume = salesTotalVolume;
	}
	public int getSalesMonthlyVolume() {
		return salesMonthlyVolume;
	}
	public void setSalesMonthlyVolume(int salesMonthlyVolume) {
		this.salesMonthlyVolume = salesMonthlyVolume;
	}
	public int getProductState() {
		return productState;
	}
	public void setProductState(int productState) {
		this.productState = productState;
	}
}
Alaska_Lee 2015-07-31
  • 打赏
  • 举报
回复
引用 1 楼 a510835147 的回复:
productList里面没数据好吗? 你没在迭代里面将对象添加至productList集合
productList里面是有数据的,直接从数据库获取的,我单步调试过。 List<Product> productList = ProductDao.listProducts(); //从数据库读取
隔岸望秋水 2015-07-31
  • 打赏
  • 举报
回复
<c:foreach> items属性没取到值吧
Janze- 2015-07-31
  • 打赏
  • 举报
回复
product里面有没有get和set方法?
迷林 2015-07-31
  • 打赏
  • 举报
回复
你要取的值在这里面 productList 怎么跑到Product这去取了??
_追逐梦想_ 2015-07-30
  • 打赏
  • 举报
回复
productList里面没数据好吗? 你没在迭代里面将对象添加至productList集合

679

社区成员

发帖
与我相关
我的任务
社区描述
智能路由器通常具有独立的操作系统,包括OpenWRT、eCos、VxWorks等,可以由用户自行安装各种应用,实现网络和设备的智能化管理。
linuxpython 技术论坛(原bbs)
社区管理员
  • 智能路由器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧