• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shopping cart application using struts

 
Santhini Nesaraj
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Struts forum.
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic