Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Shopping cart application using struts

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 67601
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the Struts forum.
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic