Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read arrayList content using JSTL

Tags:

jsp

servlets

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

like image 963
Developer_H Avatar asked Sep 23 '26 07:09

Developer_H


1 Answers

It should be :

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

Note: No <jsp:useBean> required.

like image 177
skaffman Avatar answered Sep 25 '26 20:09

skaffman



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!