How to iterate over a list of strings sent from a controller to jsp

I call "addObject" ModelAndView as follows: modelAndView.addObject("userNames", userNames); The second argument is an ArrayList of strings. How can I iterate over this list on a JSP page?

This is what I have, but it does not work:

 <select id="users"> <c:forEach var="userName" items="${userNames}"> <option>${userName}<option/> </c:forEach> </select> 

Do I need to add tag imports to use elements in the c tag?

+4
source share
1 answer

You tried:

 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

The c: forEach tag is in the core JSTL library. If you have not already done so, you will also need jstl.jar in your build path.

+5
source

Source: https://habr.com/ru/post/1400099/


All Articles