我在开始页面中把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 exceptionjava.lang.ClassCastExceptionat org.apache.jsp.search_0005fresult$jsp._jspService(search_0005fresult$jsp.java:72)
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 exceptionjava.lang.ClassCastExceptionat org.apache.jsp.search_0005fresult$jsp._jspService(search_0005fresult$jsp.java:72)
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;
}
}