Vector on JSP Page

How can I iterate over a vector in a JSP page?

I have done this:

<%
 Vector value = (Vector) request.getAttribute("status");
 for (Enumeration e = value.elements(); e.hasMoreElements(); )
 {
        StatusItem myStatus = (StatusItem) e.nextElement();

 }
%> 

Is there a way to do this using jsp tags? thank

+3
source share
2 answers

Print the contents of this vector as follows:

<c:foreach var="myStatus" items="${status}" >
  <!-- print out the value of each status in the vector.
       Method getValue() must exist in the status class.-->
  <c:out value="${myStatus.value}"/>
</c:foreach>
+2
source

You can <c:forEach>iterate jstl tag collections :

<c:forEach var="s" items="${status}">
    item is: ${s}
</c:forEach>
+1
source

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


All Articles