List object and foreach
843840Dec 18 2007 — edited Dec 18 2007Hello, I have the following code on my Student class:
public static List<Student> getAllStudents() {
EntityManager em = SingletonDAO.getInstance().getEntityManager();
Query q = em.createQuery( "SELECT c FROM students c" );
List<Student> students = q.getResultList();
return students;
}
The method above just return a List of Student that are on my database. This method is static, and i don't have an allStudent field of course.
I would like to know if is possible to iterate between this list in a foreach JSTL tag. I would like to do something like that:
<c:forEach var="eachStudent" items="${Student.getAllStudents()}" >
<c:out value="${eachStudent}"></c:out><br>
</c:forEach>
I know that the code above doesn't work, but i would like to do something similar to that. Which is the best way to do that?
Thank you, and sorry about my english.