• Post Reply Bookmark Topic Watch Topic
  • New Topic

HashMap to HTML?  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



this is the for loop I used before

 
Author and ninkuma
Marshal
Posts: 66729
167
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 1991
265
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 21378
91
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Oh. Hi guys! Look at this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!