java - Instantiating object only once upon multiple calls without using static -
all want instantiate object of list once upon multiple calls servlet. please without use of static keyword not allowed here.
list<cart> list=new arraylist<cart>(); list.add(new cart(name, cost)); httpsession s=req.getsession(); s.setattribute("list",list); out.println("item added cart"); out.println("\n<a href=\'viewserv\'>view cart</a>"); out.println("\n<a href=\'item\'>view item</a>");
as storing session, need check weather there in session or not .
httpsession s=req.getsession(); if(s.getattribute("list") !=null){ sessionlist =new arraylist<cart>();/create new }else { sessionlist = (list)s.getattribute("list"); sessionlist.add(.... }
Comments
Post a Comment