Results 1 to 8 of 8
-
02-17-2005, 11:10 PM #1New Member
- Join Date
- Feb 2005
- Posts
- 4
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
-
02-17-2005, 11:24 PM #2Web Hosting Master
- 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.webmaster A T 420th.com
What is my Itunes playing? Visit 420th.com/nowplaying.jsp to find out.
Ask the monkey: http://www.monkeyfaq.com
-
02-17-2005, 11:42 PM #3New Member
- Join Date
- Feb 2005
- Posts
- 4
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..
-
02-18-2005, 12:21 AM #4Web Hosting Master
- 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());
}webmaster A T 420th.com
What is my Itunes playing? Visit 420th.com/nowplaying.jsp to find out.
Ask the monkey: http://www.monkeyfaq.com
-
02-18-2005, 05:17 PM #5Web Hosting Evangelist
- Join Date
- May 2004
- Posts
- 465
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
-
02-20-2005, 08:20 PM #6New Member
- Join Date
- Feb 2005
- Posts
- 4
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???
-
02-20-2005, 09:20 PM #7Web Hosting Evangelist
- Join Date
- May 2004
- Posts
- 465
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
-
02-21-2005, 01:37 AM #8New Member
- Join Date
- Feb 2005
- Posts
- 4
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... ??