Developer_H
Developer_H

Reputation: 33

how to read arrayList content using JSTL

I want to read the arrayList objects Attributes that is assigned to request object from JSTL how can I do this? i tryed the following

here is the servlet code:

ArrayList<Employee> al = new ArrayList<Employee>();
/* code for filling the ArrayList with objects from class Employee */
request.setAttribute("alldata", al);`

In my JSP page:

<jsp:useBean id="alldata" class="java.util.ArrayList" scope="request">
<c:forEach items="alldata" var="item">
<c:out value="item.getName()"></c:out>
</c:forEach>
</jsp:useBean>

but it's not working,

Thanks in advance

Upvotes: 3

Views: 11906

Answers (2)

Pokuri
Pokuri

Reputation: 3082

use EL expression

<c:out value="${item.name}"></c:out>

Upvotes: 0

skaffman
skaffman

Reputation: 403491

It should be :

<c:forEach items="${alldata}" var="item">
  <c:out value="${item.name}"/>
</c:forEach>

Note: No <jsp:useBean> required.

Upvotes: 3

Related Questions