Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vector in JSP page

Tags:

java

jsp

How I can iterate a vector in a JSP page?

I have done it:

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

 }
%> 

Is there any way to do it with jsp tags? Thx

like image 463
Jjreina Avatar asked Mar 31 '26 00:03

Jjreina


2 Answers

Print out the contents of the vector like this:

<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>
like image 61
dogbane Avatar answered Apr 02 '26 12:04

dogbane


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

<c:forEach var="s" items="${status}">
    item is: ${s}
</c:forEach>
like image 24
Bozho Avatar answered Apr 02 '26 14:04

Bozho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!