How can I get through the JSP? (Association of hibernates)

So, I'm pretty new to JSP. I tried this in several ways. Ways that would make sense in PHP or automation systems ... I probably think too much really ...

I have a sleeping friend for many associations. This class x has many classes y. In class x view.jsp. I would like to capture the whole class y, where the foreign key y matches the primary key x and displays them. Hibernate seems to correctly put this stuff into a set. Now the question is how can I iterate over this set and then output its contents ...

I'm here somehow stalled. I tried to write a scriptlet,

<% java.util.Iterator iter = aBean.getYs().iter(); // aBeans is the bean name // getYs would return the set and iter would return an iterator for the set while(iter.hasNext) { model.X a = new iter.next() %> <h1><%=a.getTitle()%></h1> <% } %> 

It would seem that something should work? Hmmmmmm

+4
source share
1 answer

It is better to put the bean attribute as a request (or session) and iterate over it using JSTL:

 <c:forEach items="${bean.ys}" var="item"> <h1>${item.title}</h1> </c:forEach> 
+9
source

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


All Articles