I am trying to iterate over a list and trying to print the value as:
<jsp:useBean class="com.lftechnology.db.EmployeeDaoImpl" id="empImpl"></jsp:useBean>
<jsp:useBean class="com.lftechnology.employee.Employee" id="employee"></jsp:useBean>
<%
List<com.lftechnology.employee.Employee> empList = null;
empList = empImpl.getAllEmployee();
out.println(empList.size());
%>
<c:forEach items="${empList}" var="element">
<tr>
<td>${element.name}</td>
<td><c:out value="${element.name}" /></td>
</tr>
</c:forEach>
However, only the size of the list is printed not the name as defined inside jstl. Any help? I want to print the all the attributes of employee object.
Why do you use the scriptlet at all? Something like this should work (I could not test it):
Some background
Just declaring a variable in a scriptlet does not automatically make it available to the JSTL runtime. In fact JSTL works on the
pageContextinjected into each JSP at runtime by the container. So if you really need to declare a variable in a scriptlet and want to make it available to JSTL you have to do this explicitly: