当前位置:编程学习 > JAVA >>

J2EE购物车问题

//把商品放入购物车中 
@RemoteMethod
    public void addLampToCart(Integer lampId){
     List<LampVo> list = (List)ActionContext.getContext().getSession().get("listLamps");
     System.out.println("-----------"+list.size());
     if(list.size() == 0){
      list = new ArrayList<LampVo>();
     }
     LampVo lampVo = lampService.detailsLamp(lampId);
     list.add(lampVo); 
     ActionContext.getContext().getSession().put("listLamps", list);
    }

    
为什么运行起来就是不行啊....
List<LampVo> list = (List)ActionContext.getContext().getSession().get("listLamps");这句有问题...请高手指教啊?? --------------------编程问答-------------------- 你确定在你的session里面有 key为listLamps的这个list对象吗? --------------------编程问答--------------------
引用楼主 adongshahua 的回复:
//把商品放入购物车中 
@RemoteMethod
    public void addLampToCart(Integer lampId){
     List<LampVo> list = (List)ActionContext.getContext().getSession().get("listLamps");
     System.out.println("--------……

 
Map<String,Object> shoppingCat=ActionContext.getContext().getSession().get("listLamps");
if(shoppingCat!=null)
   shoppingCat=new HashMap<String,Object>();

在java代码中获取一个Session是一个Map类型的 --------------------编程问答--------------------
引用 2 楼 java18 的回复:
引用楼主 adongshahua 的回复:
//把商品放入购物车中
@RemoteMethod
public void addLampToCart(Integer lampId){
List<LampVo> list = (List)ActionContext.getContext().getSession().get("listLamps");
System.out.println("……


获得session之后 有get方法 这个方法的方法值 可以是楼主添加进去的 list集合 --------------------编程问答-------------------- List<LampVo> list = (List<LampVo>)ActionContext.getContext().getSession().get("listLamps");
试下这个试试
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,