aspose file tools*
The moose likes Struts and the fly likes Shopping cart application using struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Shopping cart application using struts" Watch "Shopping cart application using struts" New topic
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: 60059
    
  65

Moved to the Struts forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Shopping cart application using struts
 
Similar Threads
Why doesn't exercise 8-1 from Murach's Java Servlets work for me on IE7?
Online Shopping
My Shopping cart does not work
Checking the size of an ArrayList in a JSP page
Problem with a shopping cart application using Stripes