jsp如何循环遍历对象中的集合
在request.setAttribute中放入一个对象,如何做到在jsp页面中打印出对象中的集合?代码如下:booleanww=false;CartShopshop=(...
在request.setAttribute中放入一个对象,如何做到在jsp页面中打印出对象中的集合?代码如下:
boolean ww = false;
CartShop shop = (CartShop)request.getAttribute("ca");
if(shop==null){
shop = new CartShop();
}else{
ww = shop.count(id);
}
if(!ww){
shop.add(mb2);
request.setAttribute("ca", shop);
}
注:mb2是JavaBean对象,shop.add是我在别的类中写的方法,实现将mb2添加到集合中。
麻烦各位大大给解决下。。偶还是个菜鸟...
public class CartShop {
ArrayList list = new ArrayList();
public void add(mybean2 mb2){
list.add(mb2);
}
public boolean count(int id){
Iterator it = list.iterator();
boolean q = false;
while(it.hasNext()){
mybean2 mb2 = (mybean2)it.next();
int ids = mb2.getId();
if(ids==id){
int w = mb2.getCount();
w++;
mb2.setCount(w);
break;
}
}
return q;
}
}
这是shop页代码,在jsp页中用foreach打印不出来。。因为shop是对象= =·再次麻烦大大们解答下。偶还是不明白 展开
boolean ww = false;
CartShop shop = (CartShop)request.getAttribute("ca");
if(shop==null){
shop = new CartShop();
}else{
ww = shop.count(id);
}
if(!ww){
shop.add(mb2);
request.setAttribute("ca", shop);
}
注:mb2是JavaBean对象,shop.add是我在别的类中写的方法,实现将mb2添加到集合中。
麻烦各位大大给解决下。。偶还是个菜鸟...
public class CartShop {
ArrayList list = new ArrayList();
public void add(mybean2 mb2){
list.add(mb2);
}
public boolean count(int id){
Iterator it = list.iterator();
boolean q = false;
while(it.hasNext()){
mybean2 mb2 = (mybean2)it.next();
int ids = mb2.getId();
if(ids==id){
int w = mb2.getCount();
w++;
mb2.setCount(w);
break;
}
}
return q;
}
}
这是shop页代码,在jsp页中用foreach打印不出来。。因为shop是对象= =·再次麻烦大大们解答下。偶还是不明白 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询