session传对象的问题

binhai1980 2006-01-09 02:00:30
我在开始页面中把col是Collection类型的对象 放在session中
session.setAttribute("product",col);

在另一个页面中
Collection coll =session.getAttribute("product");
编译时有错
我改成
Collection coll=(Collection)session.getAttribute("pruduct");
Iterator it=coll.iterator();
while(it.hasNext()){
ProductInfo pi=(ProductInfo)it.next();
。。。。
。。。
编译通过
但运行时ProductInfo pi=(ProductInfo)it.next();这句话有异常
ApplicationDispatcher[/demo]: Servlet.service() for servlet debugjsp threw exception

java.lang.ClassCastException

at org.apache.jsp.search_0005fresult$jsp._jspService(search_0005fresult$jsp.java:72)
...全文
194 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluelily22 2006-01-09
  • 打赏
  • 举报
回复
错误提示,类型不匹配,
同意楼上的看法
jgsfy 2006-01-09
  • 打赏
  • 举报
回复
这个页面中import了含有ProductInfo类的包没有?
numen_wlm 2006-01-09
  • 打赏
  • 举报
回复
严重怀疑放入的都是ProductInfo对象
binhai1980 2006-01-09
  • 打赏
  • 举报
回复
是啊
superslash 2006-01-09
  • 打赏
  • 举报
回复
col中放入的都是ProductInfo对象吗?
binhai1980 2006-01-09
  • 打赏
  • 举报
回复
ProductInf是产品信息的类
package strutsdemo;

public class ProductInfo {
private String product_id;
private String product_name;
private String price;
private String vip_price;
private String supplier;
private String stockpile;
private String description;
public void setProduct_id(String product_id){
this.product_id=product_id;
}
public String getProduct_id(){
return product_id;
}
public void setProduct_name(String product_name){
this.product_name=product_name;
}
public String getProduct_name(){
return product_name;
}
public void setPrice(String price){
this.price=price;
}
public String getPrice(){
return price;
}
public void setVip_price(String vip_price){
this.vip_price=vip_price;
}
public String getVip_price(){
return vip_price;
}
public void setSupplier(String supplier){
this.supplier=supplier;
}
public String getSupplier(){
return supplier;
}
public void setStockpile(String stockpile){
this.stockpile=stockpile;
}
public String getStockpile(){
return supplier;
}
public void setDescription(String description){
this.description=description;
}
public String getDescription(){
return description;
}
}

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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