JSTL limit forEach

If im doing c:forEach and outputting the results is there a way to limit the number of results you can display ?

many thanks.
LVL 18
Who is Participating?
i would prefer to limit the results in the model itself. I mean, you should pass only those "items" you wish to display.
Or you can limit it using local variables like in the following link
Eternal_StudentAuthor Commented:
ok, I tried something like this:

<gc:moviesList var="movies" />
            <c:forEach var="movie" items="${movies}" varStatus="status">                  
                  <c:if test="${status.count = }">
                        <a href="/sctv/movie.jsp?movieId=<c:out value="${movie.ID}" />"><c:out value="${movie.title}" /></a>

But im not sure how would set the status.count to equal 3. So it ONLY pulls out three results ?

Eternal_StudentAuthor Commented:
<c:if test="${status.count <= 3 }">

I got it ^. Thanks for the link fargo.
good that it works. But why grade B?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.