Results 1 to 8 of 8
  1. #1

    remove item in shopping cart in JSP

    hi evrybody...
    need ur help.. reagrding shopping cart.. i tried to delete the item in the cart but to still cannot.. there stg wrong w my code.. i reference this code in a book called "Javaserver Pages- fast&easy web development" and still cannot work...

    can anyone help..???

    below are my codes..

    in the java file.. -----------------------------------------------------------

    public void removeItem(String id){
    System.out.println("\n\n Id = " + id);
    Enumeration productEnum = getProducts();
    while(productEnum.hasMoreElements()){
    Product product = (Product)productEnum.nextElement();
    System.out.println("\n\n product id = " + product.getId());
    if(product.getId().equals(id)){
    System.out.println("\n\n halow product id = " + product.getId());
    products.removeElement(product);
    }
    }
    }


    ---------------------------------------------------------

    when i tried this code .. to remove the item 608881 in the cart.. the output is these...

    Id = 608881
    [2/18/05 8:25:42:870 GMT+08:00] 26190139 SystemOut O

    product id = 349
    [2/18/05 8:25:42:870 GMT+08:00] 26190139 SystemOut O

    product id = 608881

  2. #2
    Join Date
    Dec 2002
    Location
    NY, NY
    Posts
    3,974
    you dont need to do "\n\n for every line
    the method println does that [print line..]

    what does product.getId return?
    if it returns a string, you need to parse that into an into, and then compare using equals

    like
    int arg_id = Integer.parseInt(id);
    int prod_id = Integer.parseInt(product.getId());
    if(arg_id == prod_if){
    products.removeElement(product);
    }

    also.. you may want to check as to how you do the getProducts() method.
    Are you sure it returns the correct enumeration?
    try scrolling through the whole enumeration, and printing it to see if it is correct..
    Enumeration productEnum = getProducts();
    while(productEnum.hasMoreElements()){
    System.out.println("PROD ID = " + ((Product)productEnum).getId());
    }

    check it.. return here with the results.

  3. #3
    oo... the product.getId is a String ...

    i already alter the codes into this

    Enumeration productEnum = getProducts();
    while(productEnum.hasMoreElements()){
    System.out.println("PROD ID = " + ((Product)productEnum).getId());

    and error is displayed..


  4. #4
    Join Date
    Dec 2002
    Location
    NY, NY
    Posts
    3,974
    whats the error?
    did u finish the second scope?
    Enumeration productEnum = getProducts();
    while(productEnum.hasMoreElements()){
    System.out.println("PROD ID = " + ((Product)productEnum).getId());
    }

  5. #5
    OK, experts. Depends on type of container and compiler you use you may need to recompile your JSP code first. Check your work area.
    Open Solution, Inc
    http://opensolution-us.com

  6. #6
    ok.. i think that's the problem.. i'm using websphere prog.. in my company... and i face this problem.. but when i tried it at home using Sun One Microsystem prog... actually i can run.. hmm.. so different prog have different configuration... m i right to say that???

  7. #7
    yes. in this case it depends on the WebSphere version. You may need to find a work area in container and remove all compiled JSP pages (classes and *.java files). It will slow you for the first time when you will invoke any removed JSP page, but it will allow you to eliminate one of the variables in debugging your problem.

    Peter Kinev.
    Open Solution, Inc
    http://opensolution-us.com

  8. #8
    Originally posted by pnorilsk
    yes. in this case it depends on the WebSphere version. You may need to find a work area in container and remove all compiled JSP pages (classes and *.java files). It will slow you for the first time when you will invoke any removed JSP page, but it will allow you to eliminate one of the variables in debugging your problem.

    Peter Kinev.

    thanks for the reply.. i'm using websphere studio site developer.. and this s/w is a new thingy for me.. so how do i find this work area in container... ??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •