JSP: Iterate over List and get each item (ForEach)

I am having a hard time iterating over a List with jsp. I did this several times with velocity, but I somehow can’t get it to work with jsp.

This is an easy example I am trying to get to work:

       @RequestMapping("/bye")
    public ModelAndView byeWorld() {
        String message = "Goodbye World, Spring 4.1.2!";

        List<Map<String, Object>> data = dataProvider.getVorgaengeGesamtByArkNr();

        model.put("table", data);
        model.put("columnNames", utils.getColumnNames(data));
        return new ModelAndView("test", model);
    }

utils.getColoumnNames returns an List.

This is the lopp in the .jsp:

<c:forEach var="entry" items="${columnNames}">
    <tr>
        entry
    </tr>
</c:forEach>

Response looks like this:

    <c:forEach var="entry" items="[ARKNR_ABTEILUNG, LIEFERANT_ID, LIEFERANT_NAME, RECHNUNGS_NR, RECHNUNGS_DATUM, RECHNUNGS_EINGANG, STATUS_ID, STATUS_NAME_DE, RECHNUNGS_BETRAG_BRUTTO, RECHNUNGS_BETRAG_WAEHRUNG, SKONTO, WEITERBERECHNUNG, ARCHIV_ID, PROZESS_ID, AKTUELLER_BENUTZER, AKTUELLER_BENUTZER_ID, RECHNUNG_ID, KV_ID, ARKNR, DEPARTMENT_ID, FIBU_NAME, DBRD_ID]">
    <tr>
        entry
    </tr>
</c:forEach>

So the list is just replacing ${columnNames}, not looping through it at all.


Source: jsp

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.