Web Hosting Talk







View Full Version : remove item in shopping cart in JSP


syidah
02-17-2005, 11:10 PM
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

ilyash
02-17-2005, 11:24 PM
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.

syidah
02-17-2005, 11:42 PM
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..

:bawling:

ilyash
02-18-2005, 12:21 AM
whats the error?
did u finish the second scope?

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

pnorilsk
02-18-2005, 05:17 PM
OK, experts. Depends on type of container and compiler you use you may need to recompile your JSP code first. Check your work area.

syidah
02-20-2005, 08:20 PM
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???

pnorilsk
02-20-2005, 09:20 PM
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.

syidah
02-21-2005, 01:37 AM
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... ??