I am making a shopping cart java program and what I want to do is be able to add to cart and it will display the item. When i add a new item i want it to stack one after another. I tried this in a servlet and i used a for loop to get it to work the way I wanted to, but I want the hashmap values of name and price to be posted on to the html page that i created. Is this possible?
Why aren't you using JSP to generate the views? Doing so in Java strings in a servlet is almost impossible to do correctly, in addition to just being a flat-out poor practice.
Is this for an assignment where you can't use JSP?
I totally agree with Bear - don't embed the HTML in your servlet. Spend a couple of hours learning JSP and JSTL - the payoff will be greater than the investment.
Also, prefer to iterate over the entrySet() and then get the key and value of each entry instead of iterating over the keySet() and then using get(key).