Convert keys and values ​​from a HashMap to an HTML table with java

advertisements

I have a HashMap which looks like the following:

HashMap<String, Integer> jcbs = new HashMap<String, Integer>();

The key is a String, the Value an Integer.

Now I have a html-file in which there is a table.

What I need to do now, is to fill all the keys and values of the HashMap into this html table.


<%

    StringBuilder stringMapTable = new StringBuilder();
    stringMapTable.append("<table>");

    Iterator it = jcbc.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pair = (Map.Entry)it.next();
            stringMapTable.append("<tr><td>" + entry.getKey() + "</td><td>" +entry.getValue() + "</td></tr>");
            System.out.println(pair.getKey() + " = " + pair.getValue());
            it.remove(); // avoids a ConcurrentModificationException
        }

  String mapTable = stringMapTable.toString();

%>

In HTML

<%=mapTable %>