| Author |
Shopping cart application using struts
|
Santhini Nesaraj
Greenhorn
Joined: May 16, 2005
Posts: 9
|
|
Hi, I am a Java begininer. I am doing an assignment on shopping cart using Struts framework. so I created an ArrayList in the action class. This is to add the items to the cart. But there is some error in the arraylist which I coudlnt fix. And I need to create a JSP file that will indicate that how many items are added to the cart each time an item is selected, How do I do that using JSP ? Need a quick reply. Here I have pasted the code of the action class I created . It shows some error on this code. I couldnt fix it: public class ItemAddToCartAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); try{ if(session.getAttribute("cart")== null){ ArrayList cart= new ArrayList(); Hashtable item= new Hashtable(); item.put("brand",cart); item.put("color",cart); item.put("size",cart); item.put("price",cart); item.put("shipping",cart); cart.add(item); session.setAttribute("cart",cart); } else (session.getAttribute("cart",cart)){ ArrayList cart=(ArrayList)session.getAttribute("cart"); } Please give me a solution to fix the error for the action class and also how to create the JSP file. Any help would be greatly appreciated. Thanks!
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
|
Moved to the Struts forum.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
alan do
Ranch Hand
Joined: Apr 14, 2005
Posts: 354
|
|
|
this is a really a java question, not struts. you have a try w/o catch and an a weird 'else' condition. what are you trying to do with "else (session.getAttribute("cart",cart)){"??? replace the whole line with just "else{" . what's the exact error that you're getting?
|
-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
|
 |
 |
|
|
subject: Shopping cart application using struts
|
|
|