I've got a Map containing a List of Users given to my jsp. I am trying to iterate through them with a <c:forEach>, and it doesn't like it. My User object is a simple JavaBean. I've used <c:out> on the List within the map and I get the data. Why isn't the <c:forEach> working?
SpringappController.handleRequest()
jspCode:public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map data = new HashMap(); List users = getUserManager().getUsers(); data.put("users", users); logger.info("Users: " + users); return new ModelAndView("hello", "data", data); }
outputCode:<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> <html> <body> <c:forEach items="${data.users}" var="user"> <c:out value="${user}"/><br/> </c:forEach><br/> <c:out value="${data.users}"/><br/> <c:out value="${data.users[0].username}"/> - <c:out value="${data.users[0].age}"/><br/> <c:out value="${data.users[1].username}"/> - <c:out value="${data.users[1].age}"/><br/> <c:out value="${data.users[2].username}"/> - <c:out value="${data.users[2].age}"/><br/> </body> </html>
HTML Code:<html> <body> ${data.users}<br/> <br/> [business.User@18f1be9, business.User@717d91, business.User@eafb71]<br/> Matt - 27<br/> Jonathan - 24<br/> Zac - 19<br/> </body> </html>


Reply With Quote

