File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes printing values from hashtable on a JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "printing values from hashtable on a JSP page" Watch "printing values from hashtable on a JSP page" New topic
Author

printing values from hashtable on a JSP page

Sourabh Jahagirdar
Greenhorn

Joined: Jan 04, 2013
Posts: 4
Hi,

I have created a shopping cart application using jsp and servlets.

I am able to add items to shopping cart.

But I want to show the items on "View Shopping Cart" jsp page in following table format.

Item | Quantity | Price

book1 | 1 | 100
book2 | 2 | 200

Total | 3 | 300

Also I want "updateQuantity()" and "removeFromCart()" functions in "ViewCart.jsp" page.

How should I do it?



The code for the pages is as follows.



----------------------------
ShoppingCart.java




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

Product.jsp





Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

You are using a lot of old and obsolete technology that needs to be updated. Hashtables should be replaced with Map implementations, and your JSP should not contain obsolete Java scriptlets; use the JSTL and EL instead. Please see this JspFaq entry.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sourabh Jahagirdar
Greenhorn

Joined: Jan 04, 2013
Posts: 4
Hi,

Thanks, I will use JSTL and EL.

Just I want to print the output in the table format.

Please help for that.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

To loop over a list, you'd use the JSTL's <c:forEach> action. For each iteration you'd likely create a row (<tr>) of the table. For each individual value in whatever's in the list (an array? a bean?) you'd create a <td> using the EL to fill in the dynamic value.

If we know more about the data you want to show, we could be more specific.

Remember, you need to use a List, array, or Map. Hashtable won't cut it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: printing values from hashtable on a JSP page