jQuery in Action, 3rd edition
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

Shopping cart application using struts

Santhini Nesaraj

Joined: May 16, 2005
Posts: 9

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();
if(session.getAttribute("cart")== null){
ArrayList cart= new ArrayList();
Hashtable item= new Hashtable();

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.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Moved to the Struts forum.

[Asking smart questions] [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>
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Shopping cart application using struts
It's not a secret anymore!