Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

List object and foreach

843840Dec 18 2007 — edited Dec 18 2007
Hello, 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2008
Added on Dec 18 2007
2 comments
142 views