Reputation: 4445
I am new to JSP and servlet.
I am trying to have list from servlet and wants to display those data into JSP page.
Here is what I did
My Servlet class
List<User> list = friendsDao.getFirendsList(user.getEmail());
System.out.println("List Size:"+list.size());
req.setAttribute("list", list);
getServletContext().getRequestDispatcher("/home.jsp").forward(req, resp);
My JSP Page
I have added this tag library
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
and here is what I am doing to iterate the data
<table>
<c:forEach var="friend" items="${list}">
<tr>
<td><c:out value="${friend}" /></td>
<td><c:out value="${friend.email}" /></td>
</tr>
</c:forEach>
</table>
but this is not working
but when I am trying to have something like this
<%
}
List<User> list = (List<User>) request.getAttribute("list");
%>
<table>
<c:forEach var="friend" items="<%=list%>">
<tr>
<td><c:out value="${friend.name}" /></td>
<td><c:out value="${friend.email}" /></td>
</tr>
</c:forEach>
</table>
This is also not working but, it at list iterate the loop to the size of data. but in browser it prints
${friend.name} ${friend.eamil}
How can I have actual values in there. Please help me with this.
Thanks, Nixit
Upvotes: 2
Views: 161
Reputation: 4445
Ohk I got the solution,
I don't know the reason, but jsp file requires me to put this one line of code. in order to tag library to work
<%@ page isELIgnored="false" %>
Upvotes: 0
Reputation: 240918
change
<c:forEach var="friend" items="<%=list%>">
to
<c:forEach var="friend" items="${list}">
because by <%=list%>
it is outputting the value right there, and you don't need reference to List<User>
in jsp
Upvotes: 1