I am wondering how I can iterate through a list array in a jsp page, where the list is defined in a custom java servlet.
This is what I have in the servlet:
request.setAttribute("TITLE", STRINGVALUE);
I can display the above code fragment with the following line:
${dashboard}
Now I am trying to use a foreach loop:
<c:forEach var="VARIABLE" items="??????">
The question consists of two sub questions:
- How can I use an array in the foreach statement, without using scriptlets?
- How can I print values of the array elements? For example, ${person.name} results in an error, as the program only sees a String.
Basically, you need to have the List of your Objects in your session.
Ex.
And then in your jsp you use it like this:
You can also see BalusC post in Iterate over elements of List and Map using JSTL <c:forEach> tag for more info