问题描述
1。实体类packageorg.mh.fight.entity;publicclassFlightinfo{intid;Stringstart_place;Stringend_place;Stringtime;doubleprice;publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicStringgetStart_place(){returnstart_place;}publicvoidsetStart_place(Stringstart_place){this.start_place=start_place;}publicStringgetEnd_place(){returnend_place;}publicvoidsetEnd_place(Stringend_place){this.end_place=end_place;}publicStringgetTime(){returntime;}publicvoidsetTime(Stringtime){this.time=time;}publicdoublegetPrice(){returnprice;}publicvoidsetPrice(doubleprice){this.price=price;}}
2。购物车packageorg.mh.fight.util;importorg.mh.fight.entity.Flightinfo;publicclassBuyCar{Flightinfoflightinfo;intnum;publicFlightinfogetFlightinfo(){returnflightinfo;}publicvoidsetFlightinfo(Flightinfoflightinfo){this.flightinfo=flightinfo;}publicintgetNum(){returnnum;}publicvoidsetNum(intnum){this.num=num;}}
3。购物车Map:key为FlightinfoID(编号),value为buyCar里面是(Flightinfo和num),购物车Map用Session来维护//根据ID查询出相关的记录publicFlightinfoflightInfoById(Stringid,HttpSessionsession){ArrayListarrayList=(ArrayList)session.getAttribute("list");for(inti=0;i<arrayList.size();i++){Flightinfoflightinfo=(Flightinfo)arrayList.get(i);if(id.equals(flightinfo.getId())){returnflightinfo;}}returnnull;}//购物车publicbooleanbuyCar(Stringid,HttpSessionsession){try{booleanflag=false;Mapcar=null;if(session.getAttribute("buycar")!=null)car=(Map)session.getAttribute("buycar");elsecar=newHashMap();Flightinfoflightinfo=flightInfoById(id,session);Object[]key=car.keySet().toArray();for(inti=0;i<key.length;i++){if(id.equals(key[i])){BuyCarbuyCar=(BuyCar)car.get(key[i]);buyCar.setNum(buyCar.getNum()+1);flag=true;break;}}if(!flag){BuyCarbuyCar=newBuyCar();buyCar.setFlightinfo(flightinfo);buyCar.setNum(1);car.put(id,buyCar);}session.setAttribute("buycar",car);returntrue;}catch(Exceptione){//TODO:handleexceptione.printStackTrace();returnfalse;}}
4。JSP页面中<c:foreach>迭代<c:forEachitems="${sessionScope.buycar}"var="car"><tr><tdwidth="20%"height="40"><divalign="center"class="style21">F${car.value.flightinfo.id}</div></td><tdwidth="20%"height="40"><divalign="center"><spanclass="style21">${car.value.flightinfo.price}</span></div></td><tdwidth="20%"height="40"><divalign="center"class="style21">${car.value.flightinfo.time}</div></td><tdwidth="20%"height="40"><divalign="center"class="style21">${car.value.num}</div></td><s:urlaction="returnTicket.action"var="url"><s:paramname="key">${car.key}</s:param></s:url><tdwidth="20%"height="40"><divalign="center"class="style21"><s:ahref="%{url}">退票</s:a></div></td></tr></c:forEach>
------------------------------------------------------------------------------${car.value.num}这里的值可以遍历出来为什么${car.value.flightinfo.id}等实体bean不能出来~~~怎么改这里呢?